Hi,
I have a script for space switching that works for 3 inputs: 2 parents spaces and 1 child space.
However, I was wondering how to revise the code to accommodate the 4 inputs automatically (i.e. with 3 parent spaces).
I initially thought just having a conditional statement such as
If input>3:
Do this:
If input>4:
Do this:
If input>5
Do this:
But this would mean having several duplicate commands within the do this block.
Is there a better way of doing this? Thank you
The code is the following
import maya.cmds as cmds
objSel = cmds.ls(sl=True)
spaceSwitchCon = 'locator1'
# This will be affected when the the number of inputs increased
spaceSwitchConstraint = cmds.orientConstraint(objSel[0],objSel[1],objSel[2],mo=True)
# This will be affected when the the number of inputs increased
name1 = objSel[0].split('_')[-1]
name2 = objSel[1].split('_')[-1]
cmds.addAttr(spaceSwitchCon, ln = "spaceSwitch", at = "enum",en = name1 + ':' + name2 + ':')
cmds.setAttr(spaceSwitchCon + '.spaceSwitch', keyable=True)
# This will affected when the the number of inputs increased
reverse_spaceSwitch = cmds.createNode('reverse', n="reverse_" + objSel[0])
cmds.connectAttr(spaceSwitchCon + '.spaceSwitch', reverse_spaceSwitch + '.input.inputX')
cmds.connectAttr(reverse_spaceSwitch + '.output.outputX', spaceSwitchConstraint[0] + '.' + objSel[0] + 'W0')
cmds.connectAttr(spaceSwitchCon + '.spaceSwitch', spaceSwitchConstraint[0] + '.' + objSel[1] + 'W1')