Quick-Add and Connect Attributes Script

I call it, “Quick Connect”

When I’m rigging, I find myself adding a lot of float attributes and connecting them to rotation values on a driven object. Therefore, I went ahead and wrote a script that will do most of that work for me.

All you do is type in the new attribute’s name, set the driver and driven object, and click Add Attribute. It’s super easy.

It does have a few bugs, mainly revolving around not knowing what to do when there’s a lack of information, but… It’s made for me, and I know I need to supply all the information to it, so…

In other news, I’m pretty much finished with my leg rig. I’ve got the reverse foot and toe pivot controls all automated now. Now I just need to rig my walker!

Here’s the code:

import maya.cmds as cmds

if cmds.window("quickAddAttrWin",exists=True):

cmds.window("quickAddAttrWin",title="Quick Connect",s=0)


cmds.textField("attrName",pht="Attribute Name")

cmds.button(label="Set Driver",command="setDriver()")
cmds.button(label="Set Driven",command="setDriven()")

cmds.text("Driven Value")


cmds.button(label="Add Attribute",command="quickAddAttr()")

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

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

def quickAddAttr():
    temp = cmds.textField("attrName",q=1,text=1)
    attrName = temp.replace(" ","_")
    drivenVal = cmds.optionMenu("drivenVal",q=1,v=1).lower()
    print drivenVal
    cmds.connectAttr(driver + "." + attrName,str(driven) + "." + drivenVal)




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