Quick Squash Stretch

Yesterday I sketched up a quick little UI that does a task for you that normally will take a couple of minutes. It simply links either the tY or sY of a “driver” object to the scales of “driven” objects. The sX and sZ of those scales are inversed by a multiply divide node to properly maintain volume.

Check it out!

squetchUI

import maya.cmds as cmds

def setupSquetch(driver,driven):
    """
    sel = cmds.ls(sl=1,o=1)
    driver = sel[0]
    driven = sel[1]
    """
    mdNode = cmds.createNode("multiplyDivide",n="mdNode")
    cmds.setAttr(mdNode + ".op",2)
    cmds.setAttr(mdNode + ".i1x",1)
    if cmds.optionMenu('opMenu',q=1,value=1) == "Translate":
        print("it's translate")
        cmds.connectAttr(driver + ".ty",mdNode + ".i2x")
        for obj in driven:
            cmds.connectAttr(driver + ".ty",obj + ".sy")
            cmds.connectAttr(mdNode + ".ox",obj + ".sx")
            cmds.connectAttr(mdNode + ".ox",obj + ".sz")
    else:
        print("it's scale")
        cmds.connectAttr(driver + ".sy",mdNode + ".i2x")
        for obj in driven:
            cmds.connectAttr(driver + ".sy",obj + ".sy")
            cmds.connectAttr(mdNode + ".ox",obj + ".sx")
            cmds.connectAttr(mdNode + ".ox",obj + ".sz")

def squetchUI():
    if cmds.window("squetchUI",exists=1):
        cmds.deleteUI("squetchUI")
    cmds.window("squetchUI")

    cmds.columnLayout()
    cmds.text("Set Driver Type")
    cmds.optionMenu('opMenu')
    cmds.menuItem(label="Translate")
    cmds.menuItem(label="Scale")

    cmds.button(l="Set Driver",c="setDriver()")
    cmds.button(l="Set Driven",c="setDriven()")
    cmds.text("")
    cmds.button(l="Make Squash Stretch",c="setupSquetch(driver[0],driven)")
    cmds.showWindow("squetchUI")
    cmds.window("squetchUI",edit=1,wh=(100,100),tlb=1)

def setDriver():
    global driver
    driver = cmds.ls(sl=1,o=1)
    print("driver now " + driver[0])

def setDriven():
    global driven
    driven = cmds.ls(sl=1,o=1)
    print("driven now " + driven[0])

squetchUI()

 

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