Module Object

Module Object

source code

The Blender.Object submodule

New:

Object

This module provides access to the Objects in Blender.

Example:
       import Blender
       scn = Blender.Scene.GetCurrent()      # get the current scene
       cam = Blender.Camera.New('ortho')     # make ortho camera data object
       ob = scn.objects.new(cam)             # make a new object in this scene using the camera data
       ob.setLocation (0.0, -5.0, 1.0)       # position the object in the scene

       Blender.Redraw()                      # redraw the scene to show the updates.


Classes
  Object
This object gives access to generic data from all objects in Blender.
  Property
This property gives access to object property data in Blender, used by the game engine.
Functions
 
New(type, name='type')
Creates a new Object.
source code
 
Get(name=None)
Get the Object from Blender.
source code
 
GetSelected()
Get the user selection.
source code
 
Duplicate(mesh=0, surface=0, curve=0, text=0, metaball=0, armature=0, lamp=0, material=0, texture=0, ipo=0)
Duplicate selected objects on visible layers from Blenders current scene, de-selecting the currently visible, selected objects and making a copy where all new objects are selected.
source code
Variables
readonly dictionary DrawModes
Constant dict used for with Object.drawMode bitfield attribute.
readonly dictionary DrawTypes
Constant dict used for with Object.drawType attribute.
readonly dictionary IpoKeyTypes
Constant dict used for with Object.insertIpoKey attribute.
readonly dictionary PITypes
Constant dict used for with Object.piType attribute.
readonly dictionary ParentTypes
Constant dict used for with Object.parentType attribute.
readonly dictionary ProtectFlags
Constant dict used for with Object.protectFlags attribute.
readonly dictionary RBFlags
Constant dict used for with Object.rbFlags attribute.
readonly dictionary RBShapes
Constant dict used for with Object.rbShapeBoundType attribute.
Function Details

New(type, name='type')

source code 
Creates a new Object. Deprecated; instead use Scene.objects.new().
Parameters:
  • type (string) - The Object type: 'Armature', 'Camera', 'Curve', 'Lamp', 'Lattice', 'Mball', 'Mesh', 'Surf' or 'Empty'.
  • name (string) - The name of the object. By default, the name will be the same as the object type. If the name is already in use, this new object will have a number at the end of the name.
Returns:

The created Object.

Example:

The example below creates a new Lamp object and puts it at the default location (0, 0, 0) in the current scene:
       import Blender

       object = Blender.Object.New('Lamp')
       lamp = Blender.Lamp.New('Spot')
       object.link(lamp)
       sce = Blender.Scene.GetCurrent()
       sce.link(object)

       Blender.Redraw()

Note: if an object is created but is not linked to object data, and the object is not linked to a scene, it will be deleted when the Python object is deallocated. This is because Blender does not allow objects to exist without object data unless they are Empty objects. Scene.link() will automatically create object data for an object if it has none.

Get(name=None)

source code 
Get the Object from Blender.
Parameters:
  • name (string) - The name of the requested Object.
Returns:
It depends on the 'name' parameter:
  • (name): The Object with the given name;
  • (): A list with all Objects in the current scene.

Example 1:

The example below works on the default scene. The script returns the plane object and prints the location of the plane:
       import Blender

       object = Blender.Object.Get ('plane')
       print object.getLocation()

Example 2:

The example below works on the default scene. The script returns all objects in the scene and prints the list of object names:
       import Blender

       objects = Blender.Object.Get ()
       print objects

Note: Get will return objects from all scenes. Most user tools should only operate on objects from the current scene - Blender.Scene.GetCurrent().getChildren()

GetSelected()

source code 
Get the user selection. If no objects are selected, an empty list will be returned.
Returns:

A list of all selected Objects in the current scene.

Example:

The example below works on the default scene. Select one or more objects and the script will print the selected objects:
       import Blender

       objects = Blender.Object.GetSelected()
       print objects
Notes:
  • The active object will always be the first object in the list (if selected).
  • The user selection is made up of selected objects from Blender's current scene only.
  • The user selection is limited to objects on visible layers; if the user's last active 3d view is in localview then the selection will be limited to the objects in that localview.

Duplicate(mesh=0, surface=0, curve=0, text=0, metaball=0, armature=0, lamp=0, material=0, texture=0, ipo=0)

source code 

Duplicate selected objects on visible layers from Blenders current scene, de-selecting the currently visible, selected objects and making a copy where all new objects are selected. By default no data linked to the object is duplicated; use the keyword arguments to change this. Object.GetSelected() will return the list of objects resulting from duplication.

Note: This command will raise an error if used from the command line (background mode) because it uses the 3D view context.
Parameters:
  • mesh (bool) - When non-zero, mesh object data will be duplicated with the objects.
  • surface (bool) - When non-zero, surface object data will be duplicated with the objects.
  • curve (bool) - When non-zero, curve object data will be duplicated with the objects.
  • text (bool) - When non-zero, text object data will be duplicated with the objects.
  • metaball (bool) - When non-zero, metaball object data will be duplicated with the objects.
  • armature (bool) - When non-zero, armature object data will be duplicated with the objects.
  • lamp (bool) - When non-zero, lamp object data will be duplicated with the objects.
  • material (bool) - When non-zero, materials used by the object or its object data will be duplicated with the objects.
  • texture (bool) - When non-zero, texture data used by the object's materials will be duplicated with the objects.
  • ipo (bool) - When non-zero, Ipo data linked to the object will be duplicated with the objects.

    Example:

    The example below creates duplicates the active object 10 times and moves each object 1.0 on the X axis:
           import Blender
    
           scn = Scene.GetCurrent()
           ob_act = scn.objects.active
           
           # Unselect all
           scn.objects.selected = []
           ob_act.sel = 1
           
           for x in xrange(10):
                           Blender.Object.Duplicate() # Duplicate linked
                           ob_act = scn.objects.active
                           ob_act.LocX += 1
           Blender.Redraw()
    

Variables Details

DrawModes

Constant dict used for with Object.drawMode bitfield attribute. Values can be ORed together. Individual bits can also be set/cleared with boolean attributes.
  • AXIS: Enable display of active object's center and axis.
  • TEXSPACE: Enable display of active object's texture space.
  • NAME: Enable display of active object's name.
  • WIRE: Enable the active object's wireframe over solid drawing.
  • XRAY: Enable drawing the active object in front of others.
  • TRANSP: Enable transparent materials for the active object (mesh only).
Type:
readonly dictionary

DrawTypes

Constant dict used for with Object.drawType attribute. Only one type can be selected at a time.
  • BOUNDBOX: Only draw object with bounding box
  • WIRE: Draw object in wireframe
  • SOLID: Draw object in solid
  • SHADED: Draw object with shaded or textured
Type:
readonly dictionary

IpoKeyTypes

Constant dict used for with Object.insertIpoKey attribute. Values can be ORed together.
  • LOC
  • ROT
  • SIZE
  • LOCROT
  • LOCROTSIZE
  • LAYER
  • PI_STRENGTH
  • PI_FALLOFF
  • PI_SURFACEDAMP
  • PI_RANDOMDAMP
  • PI_PERM
Type:
readonly dictionary

PITypes

Constant dict used for with Object.piType attribute. Only one type can be selected at a time.
  • NONE: No force influence on particles
  • FORCE: Object center attracts or repels particles ("Spherical")
  • VORTEX: Particles swirl around Z-axis of the object
  • WIND: Constant force applied in direction of object Z axis
  • GUIDE: Use a Curve Path to guide particles
Type:
readonly dictionary

ParentTypes

Constant dict used for with Object.parentType attribute.
  • OBJECT: Object parent type.
  • CURVE: Curve deform parent type.
  • LATTICE: Lattice deform parent type. Note: This is the same as ARMATURE, 2.43 was released with LATTICE as an invalid value.
  • ARMATURE: Armature deform parent type.
  • VERT1: 1 mesh vert parent type.
  • VERT3: 1 mesh verts parent type.
  • BONE: Armature bone parent type.
Type:
readonly dictionary

ProtectFlags

Constant dict used for with Object.protectFlags attribute. Values can be ORed together.
  • LOCX, LOCY, LOCZ: lock x, y or z location individually
  • ROTX, ROTY, ROTZ: lock x, y or z rotation individually
  • SCALEX, SCALEY, SCALEZ: lock x, y or z scale individually
  • LOC, ROT, SCALE: lock all 3 attributes for location, rotation or scale
Type:
readonly dictionary

RBFlags

Constant dict used for with Object.rbFlags attribute. Values can be ORed together.
  • SECTOR: All game elements should be in the Sector boundbox
  • PROP: An Object fixed within a sector
  • BOUNDS: Specify a bounds object for physics
  • ACTOR: Enables objects that are evaluated by the engine
  • DYNAMIC: Enables motion defined by laws of physics (requires ACTOR)
  • GHOST: Enable objects that don't restitute collisions (requires ACTOR)
  • MAINACTOR: Enables MainActor (requires ACTOR)
  • RIGIDBODY: Enable rolling physics (requires ACTOR, DYNAMIC)
  • COLLISION_RESPONSE: Disable auto (de)activation (requires ACTOR, DYNAMIC)
  • USEFH: Use Fh settings in Materials (requires ACTOR, DYNAMIC)
  • ROTFH: Use face normal to rotate Object (requires ACTOR, DYNAMIC)
  • ANISOTROPIC: Enable anisotropic friction (requires ACTOR, DYNAMIC)
  • CHILD: reserved
Type:
readonly dictionary

RBShapes

Constant dict used for with Object.rbShapeBoundType attribute. Only one type can be selected at a time. Values are BOX, SPHERE, CYLINDER, CONE, and POLYHEDERON
Type:
readonly dictionary