valueSwitcher

A pythonscript to test transfering values between two animation controls.

##
## valueSwitcher
## -------------
## 17 maj 2009
## Jan-Erik "Jonne" Östman (jonne@jonne.net)
##
## www.jonne.net
##
##
## Instructions:
## -------------
## Requires TWO selected objects
## Transfers the value from object A to object B and from object B to object A.
## Used to switch controls on for instance feet in a walkcykle when creating the 
## opposite pose
##
## v0.1
##	Rough proof of concept. Worked in the test I did. 
##	Still remains to be tested "live"
##
## ---------------------------------------------------------------------------

import maya.cmds as cmds

# Get selection
sel = cmds.ls(sl=1)

# Get all keyable attributes from selected objects and add them to an array
attrListSource = cmds.listAttr(sel[0],k=1)
attrListTarget = cmds.listAttr(sel[1],k=1)


# Loop through each object and set values
for i in range(len(attrListSource)):

	## Get attribute names
	objSourceName = sel[0] + '.' + attrListSource[i]
	objTargetName = sel[1] + '.' + attrListTarget[i]

	## Get attribute values
	objSourceValue = cmds.getAttr(sel[0] + '.' + attrListSource[i])
	objTargetValue = cmds.getAttr(sel[1] + '.' + attrListSource[i])

	## Swap values
	cmds.setAttr(objSourceName, objTargetValue)
	cmds.setAttr(objTargetName, objSourceValue)


I wish to do something Great and Wonderful, but I must start by doing the little things like they were Great and Wonderful”
~ Albert Einstein