Graphics Reference
In-Depth Information
bpy.utils.unregister_module(__name__)
bpy.types.INFO_MT_add.remove(menu_func)
These are almost identical to what you saw in the previous example, just somewhat more generalized. The
biggest difference is that we are calling bpy.utils.register_module() (and the corresponding un-
register function) instead of bpy.utils.register_class() . This is simply a more general way to
write the same thing. If we have multiple classes in the module, all of the classes will be registered. For that
reason,ratherthanaspecificclassnameastheargument,thespecialvariable __name__ isused,whichreturns
the name of the current module (i.e., this script) itself.
menu_func()
The next lines in the function send the function menu_func() to be added to the interface (or removed from
it, in the case of unregister ).
def menu_func(self, context):
self.layout.operator(Bouncing_Cone.bl_idname,
icon='MESH_CONE')
This connects the operator, referred to by its bl_idname property value to the menu item in the interface.
Itplaces MESH_CONE astheicononthemenu.Theiconisborrowedfromthemenuitemforaddingaprimitive
meshcone.Notethatwiththemultilinefunction () ,youcanhaveasmuchoraslittlewhitespaceonthesecond
lines as you want. However, it's preferable to format it with previous lines for readability.
The Main Class
Moving on to the definition of the Bouncing_Cone class, you can see that creating the class begins just as
in the previous examples. Bouncing_Cone will inherit class properties from bpy.types.Operator and
AddObjectHelper :
class Bouncing_Cone(bpy.types.Operator, AddObjectHelper):
"""Add a bouncing colored cone"""
The standard variables for operators are declared and given values:
bl_idname = "object.bouncing_cone_add"
bl_label = "Bouncing Cone"
bl_description = "Add a bouncing cone"
bl_options = {'REGISTER', 'UNDO'}
The scale value from the default Add Object template is included. There's no real need to delete it, al-
though you may not choose to use it. The scale code looks like this:
scale = FloatVectorProperty(name='scale',
default=(1.0, 1.0, 1.0),
subtype='TRANSLATION',
description='scaling')
Height, Radius, Bounce, and Color Properties
Next, you're going to add a few properties specific to the bouncing cone object. We want to be able to set the
height of the cone, the radius of the cone base, the speed and height that the cone bounces, and the color of the
Search WWH ::




Custom Search