Space Switch Script

Space switching is more straightforward than I previously thought. It just requires a group above the control and below its orient group that switches between different orient constraints.

def setupSpaceSwitch(self,ctrl,a,b,longName,type):
        cmds.select(cl=1)
        cmds.addAttr(ctrl,at="float",min=0,max=1,k=1,ln=longName)
        space = cmds.group(ctrl,n=ctrl + "_SPACE")
        cmds.xform(space + ".scalePivot",t=cmds.xform(ctrl,q=1,t=1,ws=1),ws=1)
        cmds.xform(space + ".rotatePivot",t=cmds.xform(ctrl,q=1,t=1,ws=1),ws=1)
        if type == "parent":
         cmds.parentConstraint(a,b,space,mo=1)
         cmds.connectAttr(ctrl + "." + longName,space + "_parentConstraint1." + b + "W1")
         rev = cmds.createNode("reverse",n=space + "_rev")
         cmds.connectAttr(ctrl + "." + longName,rev + ".ix")
         cmds.connectAttr(rev + ".ox",space + "_parentConstraint1." + a + "W0")
        else:
            cmds.orientConstraint(a,b,space,mo=1)
            cmds.connectAttr(ctrl + "." + longName,space + "_orientConstraint1." + b + "W1")
            rev = cmds.createNode("reverse",n=space + "_rev")
            cmds.connectAttr(ctrl + "." + longName,rev + ".ix")
            cmds.connectAttr(rev + ".ox",space + "_orientConstraint1." + a + "W0")

Advertisements
Image

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s