From BlenderWiki

< Doc:Tutorials | Extensions | Python | BSoD
Revision as of 14:16, 4 April 2009 by Mindrones (Talk | contribs)
(diff) ← Older revision | Current revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Blender Summer of Documentation: Contents | Manual | Blender Version 2.41

[edit] Discussion of Blender data structures

Earlier, we talked about Blender objects and their properties. Now that we are smarter, it is time to take a deeper look. Blender objects are actually compound objects. Almost all objects consist of two parts:

  • an Object part that holds the spatial information like location, rotation and scale
  • an ObData part that contains the geometry for the graphic element. For a Mesh this is the vertices, edges and faces. For a Curve, this is a list of control points.

Now is a good time to look at the Outliner window. The Outliner shows the relationships and linkages between Blender objects.

Create a simple scene with a Cube, a Camera and a Lamp. Change one window to the OOPs window and switch to the Outliner view with View->Show Outliner if the Outliner is not already selected. The Tree structure you see is a representation of all the Blender objects in a Scene. Select View->Hide/Show All to expand the tree.

Note:: notice how all the objects in the tree are children of a Scene. More on this later.

You can get more information on the Outliner view in the manual: The Outliner.

We already know how to get the Object part of a Blender element using the Object.Get() or Object.GetSelected() methods. How do we access the ObData part of a Blender element? Easy! Each Object has an attribute called 'data' that is a reference to the Object's ObData.

Here is a simple script to print the names and types of selected objects. Create a simple scene, select the objects to view and run the script. Compare the script output with what you see in the Outliner view.

import Blender as B


# get a list of selected objects
objects = B.Object.GetSelected()

# for each object in our list
#  print its name and type
#  get the ObData part
#  print the name and type of the ObData

for i in objects:    
	print i.name, type(i)
	obdata = i.data
	print obdata.name, type(obdata)


So, in summary:

  • Blender has a list of Scenes
  • Each Scene has a list of Objects
  • Each Object has a link to an ObData