Search code examples
pythonaxismaya

How can I query a joints sao (secondary axis world orientation)? Maya Python


I want to query the sao of one joint so I can assign it to another. In this case I have managed to get the oj of the LowArm via .jot, and I'm trying to do something similar with sao.

mc.joint ('L_Hand_JNT', e=1, oj=mc.getAttr ('L_LowArm_JNT.jot'), sao='yup', zso=1)

Any help or advice would be awesome, thanks!


Solution

  • I've worked out a way to get the result that i want, and that is to create a shadingNode that has an Enum named after the orient joint command used for a specific joint, in this case the shoulder.

    if mc.objExists ('L_ShoulderOrient_NODE'): mc.delete ('L_ShoulderOrient_NODE')
    mc.shadingNode ('transform', au=1, n='L_ShoulderOrient_NODE')
    mc.addAttr ('L_ShoulderOrient_NODE', ln='jointOrient', at='enum', en='yup', k=1)
    

    The above I've added at the create joints stage after which i used the script below:

    if mc.ls ('L_Shoulder_JNT', sl=1):
        if mc.objExists ('L_ShoulderOrient_NODE.jointOrient'): mc.deleteAttr ('L_ShoulderOrient_NODE.jointOrient')
        mc.addAttr ('L_ShoulderOrient_NODE', ln='jointOrient', at='enum', en=WOB3 + WOB4, k=1)
    

    WOB3 is the up or down based on the orient choice for the primary and secondary orient, WOB4 is the UP or DOWN as chosen from the orient joint menu. The mc.ls ('L_Shoulder_JNT', sl=1), makes sure that this script is only in effect when this specfic joint is selected and changed.

    I was then able to run this script:

    JOX = mc.attributeQuery( 'jointOrient', n='L_ShoulderOrient_NODE', le=1 )
    mc.joint ('L_Hand_JNT', e=1, oj=mc.getAttr ('L_LowArm_JNT.jot'), sao=JOX[0], zso=1)
    

    Which brought all the elements together, supplying an up/down vector for newly created joints, based on that chosen at random by the user.

    All that's now left is to delete the node at the end of the process. If Anyone thinks up an alternate way of getting the upvector of a pre-existing joint and applying it as above please let me know below!

    Many thanks, Adam