Graphics Reference
In-Depth Information
The unregister function does what you'd expect it to. It unregisters the class and removes the widget
from the interface:
def unregister():
bpy.utils.unregister_class(OBJECT_OT_add_object)
bpy.types.INFO_MT_mesh_add.remove(add_object_button)
The last few lines of code are a little bit of Python-alia to call the register() function when the script is
run:
if __name__ == '__main__':
register()
That's all there is to the add-on. To change the functionality to create the single-vertex mesh you worked
with previously, the edits are very simple. The only really necessary change is to rewrite the add_object()
function to construct the mesh as follows:
def add_object(self, context):
verts = [Vector(0, 0, 0))]
edges = []
faces = []
mesh = bpy.data.meshes.new(name='Single Vertex Mesh')
mesh.from_pydata(verts, edges, faces)
add_object_data(context, mesh, operator=self)
You should also delete the scale property from the class definition, because it is not used, and change the
various labels and names in the interface to reflect the new functionality, but these changes are trivial.
Working with Custom Properties
In this section, you will build an interactive sample script from the ground up. The functionality is simple. The
scriptwillenabletheusertocreatebouncing,coloredconesin3Dspacebyusingascriptinterfacetosetvarious
parameters for the cones such as their dimensions, color, and the speed and height of their bouncing. It's not a
very practical script, but it will give you a good sense of how a Python script works with 3D assets in Blender.
Composing the Add-on
The add-on you'll create in this section is based on the same add-on template as the one described in the previ-
oussection.However,therearesignificantadditionsandchanges,particularlyinthepartofthecodethatcreates
the object.
The overall code is structured identically to the template. First, there is the bl_info assignment and the
necessary imports. The bl_info assignment is as follows:
bl_info = {
"name": "Add Bouncing Cone",
"author": "Tony Mullen",
"version": (1, 0),
"blender": (2, 6, 2),
""
Search WWH ::




Custom Search