Module Bpy_data

Module Bpy_data

source code

The bpy module. (Generic Data Access)

       # apply the active image to the active mesh
       # this script has no error checking to keep it small and readable.

       ob_act =             # assuming we have an active, might be None
       me = ob_act.getData(mesh=1)             # assuming a mesh type, could be any
       img =                    # assuming we have an active image
       for f in me.faces:
               f.image = img

       # make a new object from an existing mesh
       # and make it active
       me =['mymesh']
       ob = # new object from the mesh = ob
       # print the names of any non local objects
       for ob in sce.objects:
               if ob.lib:
                       print 'external object:',, ob.lib
       # add an empty object at each vertex of the active mesh
       ob_act =
       matrix = ob_act.matrixWorld
       me = ob_act.getData(mesh=1)
       for v in me.verts:
               ob ='Empty')
               ob.loc = * matrix                  # transform the vertex location by the objects matrix.
       # load all the wave sound files in a directory
       import os
       sound_dir = '/home/me/soundfiles/'
       sounds_new = []
       for fname in os.listdir(sound_dir):
               if fname.lower().endswith('.wav'):
                               snd = = sound_dir + fname)
                               snd = None
                       if snd:
       # Print the sounds
       for snd in sounds_new:
               print snd
       # apply a new image to each selected mesh object as a texface.
       width, height= 512, 512
       for ob in sce.objects.context:
               if not ob.lib and ob.type == 'Mesh':    # object isn't from a library and is a mesh
                       me = ob.getData(mesh=1)
                       me.faceUV = True                                        # add UV coords and textures if we don't have them.
                       # Make an image named after the mesh
                       img =, width, height)
                       for f in me.faces:
                               f.image = img

This provides a unified way to access and manipulate data types in Blender (scene, object, mesh, curve, metaball, material, texture, image, lattice, lamp, camera, ipo, world, font, text, sound, groups, armatures, actions).
libBlockSeq actions
sequence for action data
libBlockSeq armatures
sequence for armature data
libBlockSeq cameras
sequence for camera data
libBlockSeq curves
sequence for curve data, used to store Curve, Surface and Text3d data.
libBlockSeq fonts
sequence for font data
libBlockSeq groups
sequence for group data
libBlockSeq images
sequence for image data
libBlockSeq ipos
sequence for ipo data
libBlockSeq lamps
sequence for lamp data
libBlockSeq lattices
sequence for lattice data
libBlockSeq materials
sequence for material data
libBlockSeq meshes
sequence for mesh data
libBlockSeq metaballs
sequence for metaball data
libBlockSeq objects
sequence for object data
libBlockSeq scenes
sequence for scene data
libBlockSeq sounds
sequence for sound data
libBlockSeq texts
sequence for text data
libBlockSeq textures
sequence for texture data
libBlockSeq worlds
sequence for world data