Home Website Youtube GitHub

How to access the joint in code

Hi there,

How do I access the joint in the component? I want to modify the shoulder component so that the joint actually aim to the orbit_ctl.

Any tips?

Thanks!!
~J

for example to get the joints from arm_C0 component. this is the post custom step

import mgear.shifter.custom_step as cstp


class CustomShifterStep(cstp.customShifterMainStep):
    def __init__(self):
        self.name = "test"


    def run(self, stepDict):
        """Run method.

            i.e:  stepDict["mgearRun"].global_ctl  gets the global_ctl from
                    shifter rig build bas
            i.e:  stepDict["mgearRun"].components["control_C0"].ctl  gets the
                    ctl from shifter component called control_C0
            i.e:  stepDict["otherCustomStepName"].ctlMesh  gets the ctlMesh
                    from a previous custom step called "otherCustomStepName"
        Arguments:
            stepDict (dict): Dictionary containing the objects from
                the previous steps

        Returns:
            None: None
        """
        print stepDict["mgearRun"].components["arm_C0"].jointList

Also you can check the object methods and attributes with dir()

print dir(stepDict["mgearRun"].components["arm_C0"])

you will get this

['WIP', '__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_get_valid_array_list', 'absolute_att', 'active_jnt', 'addAnimEnumParam', 'addAnimParam', 'addAttributes', 'addConnection', 'addCtl', 'addFullNameParam', 'addJoint', 'addObjects', 'addOperators', 'addSetupParam', 'addToGroup', 'add_controller_tag', 'aliasRelatives', 'armChainUpvRef', 'armpit_roll_att', 'binormal', 'blend_att', 'bone0', 'bone0_shp', 'bone1', 'bone1_shp', 'color_fk', 'color_ik', 'component_jnt_org', 'connect', 'connectRef', 'connectRef2', 'connect_averageParentCns', 'connect_orientCns', 'connect_shoulder_01', 'connect_standard', 'connect_standardWithIkRef', 'connect_standardWithRotRef', 'connect_standardWithSimpleIkRef', 'connections', 'controlRelatives', 'controlers', 'ctrn_loc', 'div_cns', 'divisions', 'eff_loc', 'finalize', 'fk0_ctl', 'fk0_npo', 'fk1_ctl', 'fk1_npo', 'fk2_ctl', 'fk2_npo', 'fk_ctl', 'fk_ref', 'fullName', 'getBiNormalFromPos', 'getCompName', 'getControlRelation', 'getFullName', 'getHost', 'getName', 'getNormalFromPos', 'getRelation', 'getType', 'get_alias_relation', 'get_valid_alias_list', 'get_valid_ref_list', 'groups', 'guide', 'ikHandleUpvRef', 'ik_cns', 'ik_ctl', 'ik_ctl_ref', 'ik_ref', 'ikcns_ctl', 'index', 'initConnector', 'initControlTag', 'initialHierarchy', 'jnt_pos', 'jointList', 'jointRelatives', 'jointStructure', 'length0', 'length1', 'length2', 'line_ref', 'local_params', 'match_fk0', 'match_fk0_off', 'match_fk1', 'match_fk1_off', 'match_fk2', 'match_ik', 'match_ikUpv', 'maxstretch_att', 'mid_cns', 'mid_ctl', 'mid_ctl_twst_ref', 'model', 'n_factor', 'n_sign', 'name', 'negate', 'normal', 'options', 'parent', 'parentCtlTag', 'parent_comp', 'parent_relative_jnt', 'postConnect', 'postScript', 'preScript', 'r_params', 'relatives', 'resample_att', 'reverse_att', 'rig', 'rollRef', 'roll_att', 'root', 'roundness_att', 'rs_params', 's_params', 'scale_att', 'setRelation', 'set_ctl_ui_host', 'set_ui_host_components_controls', 'settings', 'setupWS', 'side', 'size', 'slide_att', 'softness_att', 'sq_att', 'sq_value', 'st_att', 'st_value', 'stepMethods', 'step_00', 'step_01', 'step_02', 'step_03', 'step_04', 'step_05', 'steps', 'subGroups', 't_params', 'tr_params', 'transform2Lock', 'tws0_loc', 'tws0_rot', 'tws1_loc', 'tws1_npo', 'tws1_rot', 'tws2_loc', 'tws2_npo', 'tws2_rot', 'type', 'uihost', 'upv_cns', 'upv_ctl', 'validProxyChannels', 'validateProxyChannels', 'volDriver_att', 'volume_att', 'x_axis', 'y_axis', 'z_axis']
``
1 Like

Thanks @Miquel! I saw the CustomShifterStep post on the other thread. Thanks for that. This is the post step right? I’m more curious if I’m writing a new component, how could I code the output joint to behave differently in the actual component. Like my example case for the shoulder component, I want the joint to aim at the orbit_ctl instead of receiving the matrix of shoulder_C0_ctl.

Are you already familiar with Python? What are you getting stuck on specifically?

Rather than a “new component”, I recommend duplicating an existing component, rename it, put it in a custom component directory, and then just make your edits.

What I want to ask is how I can get the output joints under “jointOrg” to behave differently ? I think I’m trying to understand how the relationship is build or connected with the output joint? looks like jointRelatives is how it’s connected? wonder is there a way to connect it differently? if not then I should build extra node to aim in the component then use jointRelatives to connect ?

Hi Javis, the reason I ask “specifically” is because your questions are very general, and I still don’t know where you are getting stuck.

wonder is there a way to connect it differently?

What is preventing you from connecting it differently? Nothing is locked or hidden from you. Is there a specific line in the code that you don’t understand? If so, what’s the line number or the code snippet you are stuck on?

Or are you getting stuck in figuring out how to rig it? In your subject line, you said “in code”.

sorry I wasn’t being specific or clear. I wasn’t getting stuck but just want to understand and learn the structure of mgear. What I want to get thru is how the relationship or connection with the joints was setup under joint_org in a component. I found I can use a post script to get the joint and change it but I want to learn how the joint got created / setup in component.

I think I found my answer to my question?

self.jnt_pos.append(["THE_CONTROL", "JOINTNAME"])

Thanks @chrislesage

To go further, self.jnt_pos = [] gets defined in ../mgear/shifter/component/__init__.py

I’m not sure how familiar you are with Python, but when you are dealing with these classes, some of the “self” variables are coming from the parent classes. In this case, some of shoulder_01 is handled during the creation of a generic Shifter component first.

Then in ../mgear/shifter_classic_components/shoulder_01/__init__.py that variable is available as it was defined in the parent class. So sometimes you have to trace a path back upwards through the parent classes to get the full answer.

In ../mgear/shifter/component/__init__.py you’ll see something like this, and near the bottom you’ll see the actual code that handles making the joint and connecting it to the mGear matrix nodes, and from there you can hopefully find all the documentation you need.

        # Joint creation
        for jpo in self.jnt_pos:
            if len(jpo) >= 3 and self.options["joint_rig"]:
                if jpo[2] == "component_jnt_org":
        ...
        ...
        ...
            # handle the matrix node connection
            if len(jpo) == 5 and self.options["joint_rig"]:
                gearMulMatrix = jpo[4]
            else:
                gearMulMatrix = True

            self.jointList.append(
                self.addJoint(jpo[0], jpo[1], newActiveJnt, uniScale,
                              gearMulMatrix=gearMulMatrix))
1 Like