ob = bpy.data.object[“Cube”]ob = bpy.data.object.get(“Cube”) # If not found, returns None gracefullyfor ob in bpy.data.objects # returns all of the objects iterabledatablock = bpy.data.lamps.new (or bpy.data.objects.new)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
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
Brief example
for p in ob.data.polygons: p.material_index = ms_index
Materials are established separate from Objects, then links are made from Objects to Materials.
mat = bpy.data.materials[“Material”]mat= bpy.data.materials.get(“Material”) # If not found, returns None gracefullymat = bpy.data.materials.new(name="Card Paper")
Assign material to an object ob
if not(ob.data.materials.get(mat.name)): ob.data.materials.append(mat) # this example adds material to all polygons in ob ms_index = ob.material_slots.find("Card Paper") for p in ob.data.polygons: p.material_index = ms_index