Home Website Youtube GitHub

Post script "changeParent" functionality

i am not sure i correctly understand what this Post script is supposed to do!

can someone give me a simple explanation?

Thank you

Sorry, what are you referring to? Do you have a link or a code snippet or something?

sure Chris

its basically one of the Post scripts that Miquel referes to, in his video lessons


import mgear.shifter.custom_step as cstp

import pymel.core as pm

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


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

            i.e:  stepDict["mgearRun"].global_ctl  gets the global_ctl from
                    shifter rig on post step
            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
        """
        # direct name parenting example
        # # pm.parent("elbowHelper_L0_root", "arm_L0_tweak5_ctl")
        # pm.parent("elbowHelper_L1_root", "arm_L0_tweak3_ctl")
        # pm.parent("elbowHelper_L2_root", "arm_L0_tweak7_ctl")

        # # pm.parent("kneeHelper_L0_root", "leg_L0_tweak4_ctl")
        # pm.parent("kneeHelper_L1_root", "leg_L0_tweak3_ctl")
        # pm.parent("kneeHelper_L2_root", "leg_L0_tweak5_ctl")

        # # pm.parent("elbowHelper_R0_root", "arm_R0_tweak5_ctl")
        # pm.parent("elbowHelper_R1_root", "arm_R0_tweak3_ctl")
        # pm.parent("elbowHelper_R2_root", "arm_R0_tweak7_ctl")

        # # pm.parent("kneeHelper_R0_root", "leg_R0_tweak4_ctl")
        # pm.parent("kneeHelper_R1_root", "leg_R0_tweak3_ctl")
        # pm.parent("kneeHelper_R2_root", "leg_R0_tweak5_ctl")

        # access to the build dictionary
        pm.parent(stepDict["mgearRun"].components["elbowHelper_L0"].root,
                  "arm_L0_tweak5_ctl")
        pm.parent(stepDict["mgearRun"].components["elbowHelper_L1"].root,
                  "arm_L0_tweak3_ctl")
        pm.parent(stepDict["mgearRun"].components["elbowHelper_L2"].root,
                  "arm_L0_tweak7_ctl")

        pm.parent(stepDict["mgearRun"].components["kneeHelper_L0"].root,
                  "leg_L0_tweak4_ctl")
        pm.parent(stepDict["mgearRun"].components["kneeHelper_L1"].root,
                  "leg_L0_tweak3_ctl")
        pm.parent(stepDict["mgearRun"].components["kneeHelper_L2"].root,
                  "leg_L0_tweak5_ctl")

        pm.parent(stepDict["mgearRun"].components["elbowHelper_R0"].root,
                  "arm_R0_tweak5_ctl")
        pm.parent(stepDict["mgearRun"].components["elbowHelper_R1"].root,
                  "arm_R0_tweak3_ctl")
        pm.parent(stepDict["mgearRun"].components["elbowHelper_R2"].root,
                  "arm_R0_tweak7_ctl")

        pm.parent(stepDict["mgearRun"].components["kneeHelper_R0"].root,
                  "leg_R0_tweak4_ctl")
        pm.parent(stepDict["mgearRun"].components["kneeHelper_R1"].root,
                  "leg_R0_tweak3_ctl")
        pm.parent(stepDict["mgearRun"].components["kneeHelper_R2"].root,
                  "leg_R0_tweak5_ctl")

I reformatted your post. You can put code between triple backticks to make it format correctly. ```

I don’t know which video it is. Did it not explain what it was doing? This script is just parenting some stuff under some other stuff. It’s impossible to know why without seeing the video, but that’s what it is doing.

It looks like some custom controls that need to follow the limbs. So parenting is one way to make them follow.

The “stepDict” is a huge dictionary that lets you access all the Shifter components via script. But in the comments for this script, “direct name parenting example”, you see you can also just parent the objects directly by name.

And all the stuff at the top:

import mgear.shifter.custom_step as cstp
import pymel.core as pm
class CustomShifterStep(cstp.customShifterMainStep):
    def __init__(self):
        self.name = "change_parent"
    def run(self, stepDict):

That is the template boilerplate code that gets created. You don’t need to use this code. You can just run whatever Python you want. But that is the class that initializes the stepDict and lets you access it.

If you create a script through the GUI in the guide, it will automatically create that template. If you make a script yourself, you would have to add it yourself, if you wanted it.

2 Likes