Grabbing skeleton info from external blend, update skeleton to be a replica.

Hey guys!

I’m wondering exactly how I could access a external skeleton/armature, and then read the data, (bone names, positions, etc etc), and then duplicate that data onto a skeleton on the current blend.

whew, what a mouthful

I think that this may be of use:

I just need a specific direction to go, and I think I got the rest.

Thanks in advance!

Hi there,

I recently had to do a lot of this kind of thing. :slight_smile:

It’s fine to load the other blend as a library (appending the object data for the armature), but whether you should do so depends on your workflow and use case. If you’re moving a single character to multiple copies, it might be better to externalize the bones to a text file or a pickle archive and go from there.

Maybe this bit of code can be of help. It looks in the same folder as the saved .blend for a JSON file, loads it, then steps through and sets all the bones. It’s not creating new bones at all, so if one is missing it’ll fail.

import bpy
import json, os

op = bpy.context.active_object

fn = os.sep.join( [[0], 'bones.json'] )

with open(fn, 'r') as fp:
    data = json.load(fp)

for b, values in data.items():
    head = values['head']
    tail = values['tail']
    roll = values['roll']
    eb =[b]
    eb.head = head
    eb.tail = tail
    eb.roll = roll

print(">> Bones loaded from %s." % fn)

If you do go the library linking route, it should be similar-- position the head and tail, set parent if necessary, and then adjust rolls. I recommend saving rolls as a world space vector, which I did not do in this code; I found that they didn’t always line up perfectly unless I oriented the bones manually after placement.

I also found I had to run [object].update_from_editmode() and [scene].update() at times to make edits stick.

Thanks for the reply!
I managed to figure most of it out, and dang is the blender api hard to use. Anywhoo, I used to load the data into the blend, and viola!

It’s almost perfect, except now I just need to figure out how copy pose data, and I’m done :smiley: :smiley: :smiley: