Posted: Thu Feb 14, 2013 1:11 am
Joined: 20 Sep 2012
Posts: 8
I'm trying to cycle through all the armatures to export them to a file. this seems easiest using bpy.data.armatures[x] instead of going through bpy.context.scene.objects and checking if each object's type is an armature. the problem I'm having is that I can't export the proper world-translated positions for each bone this way... why is there no bpy.data.armatures[0].matrix_world ?
| Code: |
>>> bpy.data.armatures[0].bones[0].head_local
Vector((-4.505608330873656e-09, 0.0, 0.0))
>>> bpy.data.objects['Armature'].data.bones[0].head_local
Vector((-4.505608330873656e-09, 0.0, 0.0))
>>> bpy.data.objects['Armature'].matrix_world
Matrix(((1.0, 0.0, 0.0, -0.8924787044525146),
(0.0, 1.0, 0.0, 1.8488168716430664),
(0.0, 0.0, 1.0, 5.216436862945557),
(0.0, 0.0, 0.0, 1.0)))
>>> bpy.data.armatures[0].matrix_world
Traceback (most recent call last):
File "<blender_console>", line 1, in <module>
AttributeError: 'Armature' object has no attribute 'matrix_world'
|
Posted: Thu Feb 14, 2013 3:58 pm
Joined: 20 Sep 2012
Posts: 8
| Code: |
>>> bpy.data.armatures[0].name
'Armature'
>>> bpy.data.objects['Armature'].name
'Armature'
>>> bpy.data.objects['Armature'].type
'ARMATURE'
>>> bpy.data.armatures[0].type
Traceback (most recent call last):
File "<blender_console>", line 1, in <module>
AttributeError: 'Armature' object has no attribute 'type'
|
WHAAAT?!??
Posted: Thu Feb 14, 2013 5:10 pm
Joined: 05 Apr 2009
Posts: 732
don't confuse objects of type armature with armature datablocks!
| Code: |
ob = bpy.context.object
print(ob.type) # e.g. 'ARMATURE'
print(ob.data) # bpy.data.armatures[...]
|
matrix_world is a property of objects, not armatures!
if you want to iterate over all armatures in current scene, use:
| Code: |
for ob in bpy.context.scene.objects:
if ob.type != 'ARMATURE':
continue
# use armature object below |
if you want ALL armature objects, you can do
| Code: |
for ob in bpy.data.objects:
if ob.type != 'ARMATURE':
continue
# use armature object below |
_________________
I'm sitting, waiting, wishing, building Blender in superstition...
Posted: Thu Feb 14, 2013 6:22 pm
Joined: 20 Sep 2012
Posts: 8
cool. that works. however I've noticed something else strange about the armature datablock. len( bpy.data.objects['Armature'].bones ) is the total number of bones in the armature, although each bone has children that are also included in that set. the program I'm writing that imports from my format is designed to have a root bone with children bones, who also have children, etc. how do I get the root bone? it's not just bpy.data.objects['Armature'].data.bone[0] because if that gets deleted, the list just shuffles down.
Posted: Fri Feb 15, 2013 1:29 pm
Joined: 05 Apr 2009
Posts: 732
Blender allows unlimited root bones. What determines whether a bone is a root bone or not? Root bones don't have parent, so you can get all root bones like:
| Code: |
| [b for b in C.object.data.bones if not b.parent] |
you may iterate over b and get all children via Bone.children_recursive
but you may want to do that yourself in case you wanna know the "level" of the children
_________________
I'm sitting, waiting, wishing, building Blender in superstition...