Sunday, May 8, 2011

multiConstrain_v0.1 - Well that was a good hour and a half spent XD

Today I saw a post that popped up on CGSociety asking if there is a way to Aim Constraint multiple objects at once to a target  (not a group, since that would just make the groups pivot constrained.). The poster could not find a solution or an available script online, nor could I after searching.

So, since I've been interested in learning MEL for a while, I decided to take a stab at developing a simple script that would allow Maya to do what he was asking. After a little research into executing MEL commands on each object in a selection individually, and using similar examples, I thought I would have a working code. The code would work for commands like translate or delete, but since aimConstraint requires a target and something to constrain to it, that wasn't working, since it would bring the target object into the selected objects loop and screw it up. Tried so many different configurations until I finally figured out a simple loop structure that worked for it.

And here's my script :)


//Batch Aim Constraint script, by Mitch Zais
//Replace "target" with the name of your target object
//Select all objects you want to aim constrain to the target and execute the script

$aimTarget = "target";
string $selection[] = `ls -sl -l`;
for ( $each in $selection ) {
aimConstraint $aimTarget $each;
}


I want to keep learning MEL, so I plan on further developing this script now as a way of learning, since as it stands there isn't much to it. I'd like to develop an options window for it and branch it out to other constraints and operations that don't allow multiple objects to be done at once.

First thing to do is allow you to just select your target object in the viewport, so people don't have to edit the target name at the top of the script. Once I do that, I'll probably upload it to CreativeCrash.com to share with people, and continually update it there.

1 comment:

  1. Not much needs changing. If you stick to the usual maya selection order, first select the target, and shift-select all the objects you wish to aimConstrain.
    Since $selection[0] is your target, then inside your loop you can do
    if($each != $selection[0]) aimConstraint $selection[0] $each;

    Nice blog by the way...
    djx

    ReplyDelete