(Python) Creating an export skeleton maker, need some advice

Hey everyone, first post so I’m sorry if this isn’t perfectly executed, but I’m working on a Python tool for Maya that will take a rig that has multiple hierarchies and create an export skeleton that is one hierarchy that’s parented to the result/driving joints of the skeleton.

I’m not new to rigging, but pretty new to writing Python script, so I’m still having trouble thinking like a programmer. So right now, I’m really just looking to make a plan of attack and just wrap my head around what needs to happen. I’ve gone through the process dozens of times and I know the order of operations to make an export skeleton and i’ve gotten to the point where I can select the root joint and create a new joint chain over it, but as far as how to list all the new joints in the right order and then parent them to the result joint, i’ve hit a wall.

My other issue is getting it to create the hierarchies in the same manner as the rig, if that makes little sense, here are pictures…(sorry they got tiny, i don’t know how to fix that yet)

here’s how one branch looks in my rig so you can see what i’m talking about, they all kind of look like this, this one more simple than the rest though. My goal is to take all the “result” joints and make an export skeleton that’s in the same positions as and parented to them that you can use to export to other programs/engines that don’t support rigs with multiple hierarchies.


right now, if i select neck_base_result_JNT and run the script, it’ll work because the chain ends and you’ll just get a copy of the result joints, however if you select Root_Transform_CTRL and hit the button that pops up when you run the script, it’ll select every joint in the rig and arrange them like this. My issue is figuring out a way to tell it to build it like it’s built in the rig.


this is what it’s supposed to look like…


Obviously, I haven’t done the constraint part yet, but i figure if i can figure out how to list all the new joints in the right order, i can figure out the parenting part.

and then for fun, here’s what I have so far, it creates a little UI button because I was bored…


import maya.cmds as cmds


def JMSexportSkeletonMakerUI():
    
    if cmds.window("EskelMakerWindow", exists=True):
        cmds.deleteUI("EskelMakerWindow", window=True)
        
    if cmds.windowPref("EskelMakerWindow", exists=True):
        cmds.windowPref("EskelMakerWindow", remove=True)
    
    cmds.window("EskelMakerWindow", title="eskelmkr", \
    sizeable=False, minimizeButton=False, maximizeButton=False, tlc=[192, 47])
    
    cmds.columnLayout("EskelMakerWindowMainUI", parent="EskelMakerWindow")
    cmds.rowColumnLayout(nc=1, cw=[(1, 200)], p="EskelMakerWindowMainUI")
    cmds.button(l="mk n xprt skltn fm slctd jnts", bgc=(.9,.3,.1), command=lambda args:skeletonFromSelection())

    cmds.showWindow("EskelMakerWindow")

def skeletonFromSelection():
    
    cmds.select(hi=True)
    selecetObjects=cmds.ls(ap=True, sl=True, type="joint")
    cmds.select(clear=True)
    
    if selecetObjects != []:
        for each in selecetObjects:
            pos = cmds.xform(each, query=True, ws=True, rp=True, )
            cmds.joint(n=(each+"_exportJNT"), p=(pos[0], pos[1], pos[2]))
            
            
    
                    
    cmds.select(clear=True)
    
 

Your skeletonFromSelection function is going to give you results that vary based on the order of the bones in selecetObjects. You’re not deselecting after each joint call so each joint you make is going to be parented to the previous one, and the hierarchy will be a single chain based on the order of whatever came out of selecetObjects.

The problem might be simpler if you created the export skeleton at the same time as the rig and then drove it using connections and constraints. Then the output topology is independent of the rig topology and you get to control the relationship in any way you need.

[QUOTE=Theodox;25690]Your skeletonFromSelection function is going to give you results that vary based on the order of the bones in selecetObjects. You’re not deselecting after each joint call so each joint you make is going to be parented to the previous one, and the hierarchy will be a single chain based on the order of whatever came out of selecetObjects.

The problem might be simpler if you created the export skeleton at the same time as the rig and then drove it using connections and constraints. Then the output topology is independent of the rig topology and you get to control the relationship in any way you need.[/QUOTE]

thanks for the response!

So perhaps call each joint, deselect, and then parent them together after they’re placed?

As far as fixing the problem of making an export skeleton, it’s not so much that i need this tool for that, this is an hour or two of work max and can be avoided completely if you just work off one hierarchy, it’s more about me just trying to learn Python and make a tool that’s actually semi-useful for my workflow.

You’ve got the idea. You will probably find that your joints are not in a very convenient orientation the way you’re doing it, since you’ll be creating them as points . You might want to try duplicating the skeleton and pruning out the parts you don’t want instead of recreating them one at a time

[QUOTE=Theodox;25698]You’ve got the idea. You will probably find that your joints are not in a very convenient orientation the way you’re doing it, since you’ll be creating them as points . You might want to try duplicating the skeleton and pruning out the parts you don’t want instead of recreating them one at a time[/QUOTE]

ooh! that’s an interesting solution, i think i’ll look into that.

This is what i mean when i say “think like a programmer”, i’m just not able to come up with different and/or simple(er) solutions like that yet.