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

Vertex Groups

for vertexGroup in ob.vertex.groups:
  print vertexGroup.name

After establishing a group, you can add vertices to it:

verts = ((x,y,z), (x+w, y,z), (x+w,y,z+h), (x,y,z+h), \
    (x,y+t,z), (x+w,y+t,z), (x+w,y+t,z+h), (x,y+t,z+h))
faces = ((0,1,2,3), (5,4,7,6), (5,6,2,1), (6,7,3,2), (7,4,0,3), (4,5,1,0))
me = ob.data
me.name = name+'Mesh'
 
# Create mesh from given verts, faces.
me.from_pydata(verts, [], faces)
# Update mesh with new data
me.update()    
 
vg = ob.vertex_groups.new("Card Face")
vg.add([0,1,2,3],1,"ADD")
# The indexes 0,1,2,3 are referring to the vertices 
# in the order they are added to the object
blender/blenderdata.1511288110.txt.gz · Last modified: 2017/11/21 18:15 by dwheele