Graphics Reference
In-Depth Information
1. To find out what options are available to you, type bpy.ops.mesh.primitive_ into the com-
mand line, and press Ctrl+spacebar to see the autocomplete options. You'll see a list like this:
>>> bpy.ops.mesh.primitive_
circle_add(
cone_add(
cube_add(
cylinder_add(
grid_add(
ico_sphere_add(
monkey_add(
plane_add(
torus_add(
uv_sphere_add(
These method names are self-explanatory.
2. Let's add a Suzanne to the scene. Simply finish the line of code with monkey_add() like this:
>>> bpy.ops.mesh.primitive_monkey_add()
3. Voila! A monkey will appear in your scene, and the return value {'FINISHED'} will appear in the
interactive console.
An Object-ionable Question
When you do Python programming for the Blender environment, the word object may be a source of confusion .
In Python-speak, objects are instantiations of classes. (In fact, in Python, everything is an object of some class.)
This is standard terminology in object-oriented programming (OOP). On the other hand, in Blender, objects are
things that have positions, rotations, and centers in the 3D space. In short, anything you can select with your right
mouse button in Blender's Object mode is an object.
To give an example, a Mesh datablock, which contains data about the location of vertices with respect to each
other, is different from a Mesh object, which contains information about its overall location, scale, and orienta-
tion of in the 3D space. If you do not already know the difference between datablocks in Blender and the objects
to which they are associated, I recommend reviewing this before continuing with this chapter. Chapter 1,
“Blender Basics: Interface and Objects,” of my book Introducing Character Animation with Blender, 2nd Edition
(Sybex, 2011), goes into the difference for the case of meshes in some detail.
In most cases, the meaning of the word object should be clear from the context. In cases where it may not be
clear, I will refer to Blender-style objects as 3D objects .
Working with Text Editors
Theinteractiveconsoleisgreatforrunningone-linecommandsliketheonesyoujustsawandforlookingthings
up using autocomplete. In fact, if you really want to, you can even write complete scripts in the console by
pressingEnteroncefornewlinesandtwicetoreturntotheinteractivemode.Whenyouworkintheconsole,the
Python interpreter keeps track of variable values and even class definitions. However, for even simple scripts,
it is much better to work with a text editor. In this chapter, I'll assume you're using the Blender text editor, but
other good editors exist. Notepad++ is a nice editor for working with Python scripts in Windows, and for Unix-
based machines there is always Emacs. You need to be careful that the tab settings match between the editors
you use, or you'll run afoul of Python's indentation sensitivity.
Search WWH ::




Custom Search