Speed up a lot of repetetive tasks occuring in rigging, complex scene setup.
Installation:
Make a shelf button out of the code
Usage:
The function of this tool is best explained by a number of examples.
Example #1: Suppose you would like to create several joint constraints at once:
orientConstraint("ctrlThumb1", "ThumbJoint1")
orientConstraint("ctrlIndex1", "IndexJoint1")
orientConstraint("ctrlMiddle1", "MiddleJoint1")
orientConstraint("ctrlRing1", "RingJoint1")
orientConstraint("ctrlPinky1", "PinkyJoint1")
To do so, select the objects in this order:
"ctrlThumb1", "ctrlIndex1", "ctrlMiddle1", "ctrlRing1", "ctrlPinky1",
"ThumbJoint1", "IndexJoint1", "MiddleJoint1", "RingJoint1", "PinkyJoint1"
and enter this code inside Python Batch:
orientConstraint("%1", "%2")
Hit the "Preview Script" button to verify if the intended piece of code was produced, finally hit "Execute Script" to run it.
As you see the order of selection is important - do not select the %1's and %2's alternately, but first select all the %1's sequentially, then all the %2's. It works the exact same way when you use more than two placeholders. Select all the %1's, then all the %2's, all the %3's et cetera.
Note you can also use just one placeholder, for example if you want to modify an attribute, or call a function on a number of objects.
In addition to the selection name placeholders %1, %2.. there are also three special placeholders:
%i counter of the current iteration of the script
%t total number of iterations (usually equals number of selected objects divided by the number of placeholders)
%p percentage (0...1) of iterations processed
With these, you could for example gradually change a certain property over a sequence of selected objects:
Example #2: Say you would like to rotate 10 objects gradually, the last object should do a 90 degree rotation around the Y axis.
To do so, select the ten objects in sequence (for example using the outliner), then execute this script inside Python Batch:
cmds.setAttr("%1.rotationY", %p*90)
And there are more placeholders! Say you want to orient constraint a number of objects to the SAME objects, you can use the %a, %b, ... placeholders. Always select them first. The %a, %b, .. placeholders will not change for each iteration of the script:
Example #3: You would like to orient constrain objects "feather1", "feather2", ... , "feather50" to "masterControllerStart" and
"masterControllerEnd" with weights gradually changing between the two controllers from start to end.
To do so, select objects in this order:
"masterControllerStart", "masterControllerEnd", "feather1", ... "feather50"
Then run this script
cmds.orientConstraint("%a", "%1", weight = 1-%p)
cmds.orientConstraint("%b", "%1", weight = %p)
This concludes this little introduction. Note you can also use the Math.* functions to have a little fun modifying the
positions of some objects :)\