Graphics Reference
In-Depth Information
"location": "View3D > Add > Mesh > New Object",
"description": "Adds a new Mesh Object",
"warning": "",
"wiki_url": "",
"tracker_url": "",
"category": "Add Mesh"}
Most of these values are self-explanatory. If you're using the template, the versioning information (version,
blender, and API values) should be up to date. You can change the name of the script, your own author name,
the description of the script, and the category it should be classified under in the Add-ons panel. The Location
valuetellswhereintheinterfacethescriptwillbefound.Inthiscase,thefunctionalitycanbeaccessedfromthe
3D viewport's Add menu, at Add > Mesh > New Object, which is just as you saw when you used the add-on.
Module Imports
Thenextfewlinesofthecodeimportthenecessarymodules.Modulesstorethedefinitionsforclassesandfunc-
tions that are used elsewhere in the script. If you want to use a class defined in a module, the module must be
imported. As you can see, the first line
(import bpy)
imports the
bpy
module, so you can call objects that begin with the
bpy
prefix.
The next three lines,
from bpy.props import FloatVectorProperty
from add_utils import AddObjectHelper, add_object_data
from mathutils import Vector
are a little different. Rather than using the
import
command, they use the
from
X
import
Y
syntax.
This is a different way of doing the same thing that the
import
command does, but it results in a different
namingconventionwithinyourscript.Objectsimportedusingthe
from
X
import
Y
syntaxcanbeaccessed
directly by name without using any module prefix. This is a subtle but important difference. In this case, the
from
X
import
Y
syntax is used for the sake of brevity, so that object names like
FloatVectorProp-
erty
can be used without a lengthy string of prefixes. The
bpy
module is always imported using the
import
command.
Class and Function Definitions
The next part of the code, from line 21 to line 59 in the unedited template file, contains the definitions that
constitute the main portion of the code. The first definition is the definition of the
add_object()
function,
which is the block of code beginning on line 21 with
def add_object(self, context):
The next definition is the definition of the
OBJECT_OT_add_object
class, which begins on line 41 with
the line
class OBJECT_OT_add_object(bpy.types.Operator, AddObjectHelper):