2.5 Armature

Need help on finding a code to see armature in the scene. Blender 2.50. Working on export the bones from it.

bpy.context.active_object
bpy.data.armatures[n]
bpy.data.objects[n]

There a way to create bone for armature? for blender 2.50? trying to setup the bones.

In your first post you ask for a way to export bones. With Artfunkels reply and the code I posted in this thread http://blenderartists.org/forum/showthread.php?t=178510 you should be able to export them (but no animations, just the armature). If you already solved that and know how to export animations in 2.5, can you please explain how?

Later you ask how to create bones. I haven’t done that yet in python, but this thread should get you started: http://blenderartists.org/forum/showthread.php?t=164765

I did manage to export the armature with same rotation and position. Now I am just asking how to create bones to added to the armature to the scene. This deal with import the file and create the bones and then added to the scene. I don’t want to extrude the bones that would mess up the setup.

I am not good at explain how to export the animation. Since blender update the matrix that it been flip around. But first what are you trying to export with type file format.



"""
import bpy
from math import pi
import Mathutils

class VIEW3D_PT_ArmatureBoneBuild(bpy.types.Panel):
    bl_space_type = "VIEW_3D"
    bl_region_type = "TOOLS"
    bl_label = "Bone Tools"
    
    def poll(self, context):
        return context.active_object
    
    def draw(self, context):
        layout = self.layout
        #button
        layout.operator("object.BuildBone")
        layout.operator("object.UpdateBone")
        
class OBJECT_OT_BuildBone(bpy.types.Operator):
    bl_idname = "OBJECT_OT_BuildBone"
    bl_label = "Build Bone"
    __doc__ = ""
    
    def invoke(self, context, event):
        buildarmature()
        return{'FINISHED'}
        
class OBJECT_OT_UpdateBone(bpy.types.Operator):
    bl_idname = "OBJECT_OT_UpdateBone"
    bl_label = "Update Bone"
    __doc__ = ""
    
    def invoke(self, context, event):
        updatebone()
        return{'FINISHED'}        
        
def buildarmature():
    meshname ="ArmObject"
    objectname = "armaturedata"
    tmpbonename = "tmpbone"
    bfound = False
    objbone = None
    bpy.ops.object.mode_set(mode='EDIT')
    #print(dir(bpy.data))
    arm = None
    for obj in bpy.data.objects:
        if (obj.name == meshname):
            bfound = True
            arm = obj
            break
    if bfound == True:
        #print(dir(arm.data))
        bpy.ops.object.mode_set(mode='EDIT')
        bbfound = False
        for bones in arm.data.edit_bones:
            if (bones.name == tmpbonename):
                objbone = bones
                bbfound = True
                break
                
        if bbfound == True:
            print("found bone")
        
        if bbfound == False:
            newbone = arm.data.edit_bones.new(tmpbonename)
            newbone.tail.y = 1

    if bfound == False:
        armdata = bpy.data.armatures.new(objectname)
        
        ob_new = bpy.data.objects.new(meshname, armdata)
        ob_new.location.x = 2;
        bpy.context.scene.objects.link(ob_new)
        bpy.context.scene.update()
        bpy.ops.object.mode_set(mode='EDIT')
    bpy.context.scene.update()

    
def updatebone():
    objectname = "ArmObject"
    tmpbonename = "tmpbone"
    bfound1 = False
    bfound2 = False
    objbone1 = None
    objbone2 = None
    objarm1 = None
    objarm2 = None
    print("update")
    
    for obj in bpy.data.objects:
        if (obj.name == objectname):
            bfound1 = True
            objarm1 = obj
        if (obj.name != objectname) and obj.type == 'ARMATURE':
            objarm2 = obj
            bfound2 = True
            print("name:",obj.name)
    
    if (bfound1 == True) and (bfound2 == True):
        print("pass",objarm1.name," :",objarm2.name)
        
        #print(dir(objarm2.data))
        print("ARM_2 ", len(objarm2.data.bones))
        for dbones2 in objarm2.data.bones:
            print("bone name:",dbones2.name)
            objbone2 = dbones2
        print("ARM_1 ", len(objarm1.data.bones))
        for dbones1 in objarm1.data.bones:
            if (dbones1.name == tmpbonename):
                bonename = dbones1.name
                break
        
        dbones1 = objarm1.data.edit_bones[tmpbonename]
        print("bone name:",dbones1.name)
        if (dbones1.name == tmpbonename):
            dbones1.head = objbone2.head
            dbones1.tail = objbone2.tail
        print("update...bone...")
        
def register():
    bpy.types.register(OBJECT_OT_BuildBone)
    bpy.types.register(OBJECT_OT_UpdateBone)
    bpy.types.register(VIEW3D_PT_ArmatureBoneBuild)
    
def unregister():
    bpy.types.unregister(OBJECT_OT_BuildBone)
    bpy.types.unregister(OBJECT_OT_UpdateBone)
    bpy.types.unregister(VIEW3D_PT_ArmatureBoneBuild)    

if __name__ == "__main__":
    register()

This just the simple part of the creating armature. Does check if armature existing if not add into the scene. Note the select object and edit mode will not work. Trying to deal with the commands functions.

Hello!!!

I’m newbie with blender and I need the armature information with vertex influences. The ideal. Best way would be exported to a file, I need it to load it into my engine… how can I get it?

Thanks!!!

I have written the following code:

import Blender

for obj in Blender.Object.GetSelected():
    for mod in obj.modifiers:
        if (mod.type == Blender.Modifier.Types.ARMATURE):
            armature = mod[Blender.Modifier.Settings.OBJECT].getData()
            for bone in armature.bones.values():
                    print(bone.name)
    oMesh = obj.getData()
    m1_vert_count = len(oMesh.verts)
    print m1_vert_count
    for i in xrange(m1_vert_count):
        weights = oMesh.getVertexInfluences(i)
         for vertex_group, vertex_weight in weights:
            print vertex_group + vertex_weigh

But only prints this:

Bone1
Bone0
Root
3460

The mesh moves with the skeleton … I do not know why I said that they have no influences…