Module Bpy_data :: Class libBlockSeq
[hide private]
[frames] | no frames]

Class libBlockSeq

source code

Generic Data Access

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).

Get Item

To get a datablock by name you can use dictionary-like syntax.
>>> ob = bpy.data.objects['myobject']
Note that this can only be used for getting.
>>> bpy.data.objects['myobject'] = data # will raise an error

Library distinctions

Blender doesn't allow naming collisions within its own data, but it's possible to run into naming collisions when you have data linked from an external blend file.

You can specify where the data is from by using a (name, library) pair as the key.
>>> group = bpy.data.groups['mygroup', '//mylib.blend'] # only return data linked from mylib
If you want to get a group from the local data only you can use None
>>> group = bpy.data.groups['mygroup', None] # always returns local data

Sequence

These generic datablocks are sequence datatypes. They are not lists. They support the dictionary and iterator protocols. This implies the following
>>> for me in bpy.data.meshes:
...     print me.name
>>> print len(bpy.data.scenes)
>>> ob = bpy.data.objects[-1] # will raise an error
>>> ipo_list = list(bpy.data.ipos)


Instance Methods [hide private]
datablock
new(name)
fixme: need description for parameters.
source code
None
unlink(datablock)
This function removes a datablock.
source code
Instance Variables [hide private]
Datablock or None active
The active member of the datatype
Bool tag
A fast way to set the tag value of every member of the sequence to True or False
Method Details [hide private]

new(name)

source code 

fixme: need description for parameters. This function returns a new datablock containing no data or loaded from a file.

Most datatypes accept a name for their argument except for sounds, fonts, ipos and curves that need an additional argument.

The name argument is optional if not given a default name will be assigned.

The name given may be modified by blender to make it unique.

Loading From File

For images, texts, sounds, fonts types you can use the filename keyword to make a new datablock from a file.

New sounds, fonts can only be made with the a filename given.

The filename can a keyword or the second argument, use the keyword only for the datablocks new name to be set by the filename.
>>> sound = bpy.data.sounds.new('newsound', '~/mysound.wav') # uses the first string given for the name.
>>> sound = bpy.data.sounds.new(filename = '~/mysound.wav') # will use the filename to make the name.

Images

Images optionally accept extra 2 arguments for width and height, values between 4 and 5000 if no args are given they will be 256.
>>> img = bpy.data.images.new(name, 512, 512)

Curves

Curves need 2 arguments: bpy.data.curves.new(name, type) type must be one of the following...
  • 'Curve'
  • 'Text3d'
>>> text3d = bpy.data.curves.new('MyCurve', 'Text3d')

Ipos

Ipos need 2 arguments: bpy.data.ipos.new(name, type) type must be one of the following...
  • 'Camera'
  • 'World'
  • 'Material'
  • 'Texture'
  • 'Lamp'
  • 'Action'
  • 'Constraint'
  • 'Sequence'
  • 'Curve'
  • 'Key'
Objects cannot be created from bpy.data.objects; objects must be created from the scene. Here are some examples.
>>> ob = bpy.data.scenes.active.objects.new('Empty')
>>> scn = bpy.data.scenes.active
... ob = sce.objects.new(bpy.data.meshes.new('mymesh'))
Returns: datablock

unlink(datablock)

source code 
This function removes a datablock. applies to: Other types will raise an error.
Returns: None

Instance Variable Details [hide private]

active

The active member of the datatype

Applies to: This can also be used to set the active data.
>>> bpy.data.images.active = bpy.data.images.new(filename = '/home/me/someimage.jpg')
Type:
Datablock or None

tag

A fast way to set the tag value of every member of the sequence to True or False

For example
>>> bpy.data.meshes.tag = True
Is the same as...
>>> for me in bpy.data.meshes: me.tag = True
Type:
Bool