User Tools

Site Tools


Sidebar

Dan's Wiki

DokuWiki Instructions (local) DokuWiki Manual
Site Checker (Orphans Wanted)

Edit Sidebar

blender:blenderdata

This is an old revision of the document!


Blender Data Stucture

Top Level

bpy.contextContext Access
e.g., bpy.context.current_object
API Docs
bpy.dataData Access
e.g., bpy.data.objects[“Cube”]
API Docs
bpy.opsOperators
e.g., bpy.ops.object.add(<parameters>)
API Docs

Data Access

Object

To get an existing object:

  • ob = bpy.data.object[“Cube”]
  • ob = bpy.data.object.get(“Cube”) # If not found, returns None gracefully
  • for ob in bpy.data.objects # returns all of the objects iterable

To create a new object:

  • Create a datablock with datablock = bpy.data.lamps.new (or bpy.data.objects.new)
  • Create an object, linking datablock to it
  • Can also use operators to create a new object, e.g., bpy.ops.object.add

From docs, example is to create a lamp

import bpy
from mathutils import Matrix
 
scene = bpy.context.scene
 
# Create new lamp datablock
lamp_data = bpy.data.lamps.new(name="New Lamp", type='POINT')
 
# Create new object with our lamp datablock
lamp_object = bpy.data.objects.new(name="New Lamp", object_data=lamp_data)
 
# Link lamp object to the scene so it'll appear in this scene
scene.objects.link(lamp_object)
 
# Place lamp to a specified location
lamp_object.location = (5.0, 5.0, 5.0)
 
# And finally select it make active
lamp_object.select = True
scene.objects.active = lamp_object
blender/blenderdata.1511287697.txt.gz · Last modified: 2017/11/21 18:08 by dwheele