Mel scripting problem


#1

Okay guys …im Just getting into this whole scripting thing . I am setting up a rigging pipeline and I have one problem so far… How do I creat a script that will snape the pivots of my groups to specified joints no matter where they in world space . In other words not matter where I move my joints , when I hit a button I want my pivots to snape to their location …

Could anyone please help me , maybe someone has already created something for this , if so can someone direct me to its location…or perhaps someone might show me how to do it . I am not great at writing code unfortunately … Thanks any help would be greatly appreciated…


#2

Hi LionWolf,

you can e.g. try this, just change the names so they match, with your objects… :slight_smile:

delete `pointConstraint Name_Of_The_Joint Name_Of_The_Group`;

regards

Alex


#3

Try this:

/------------start------------/
global proc nn_snapPivot()
{
string $selObj[] = ls -sl;
int $size = (size($selObj) - 1);
if (!$size) {error ("Please select more than 1 object
");}

select -cl;

for ($i = 0; $i < $size; $i++){
float $tmpPos[] = xform -q -ws -t $selObj[$size];
xform -ws -piv $tmpPos[0] $tmpPos[1] $tmpPos[2] $selObj[$i];
select -add $selObj[$i];
}
}
nn_snapPivot();
/------------end------------/


#4

Hi Technofreak,

you could also write it like this… :slight_smile:

 
/*------------start------------*/
global proc nn_snapPivot()
{
	string $selObj[] = `ls -sl`;

[left]	delete `pointConstraint $selObj`;[/left]

}
nn_snapPivot();
/*------------end------------*/

since a point constrain also snaps a “pivot” to a “pivot”… saves you a couple of lines of code… :slight_smile:

regards

Alex


#5

Shouldn’t it be wrapped in a for loop, incase you have multiple objs selected, or if there is only one object selected, the code should be:


global proc nn_snapPivot()
{
	string $selObj[] = `ls -sl`;

[left]	delete `pointConstraint $selObj[0]`;[/left]

}
nn_snapPivot();


#6

Hi Mike,

if you select two objects, you don’t have to put it into a loop…

writing… -->

delete `pointConstraint $selObj`;

it just constrains the objects in the array… in this case it constrains the second selected object to the first selected object… however you could also have written…

delete `pointConstraint $selObj[0] $selObj[1]`;

however you don’t have to… :slight_smile:

regards

Alex


#7

You are correct, Alex. I wasn’t thinking it through. :argh:


#8

Hi Mike,

oki doki… :slight_smile:

btw. learned the cool trick with delete [b]melcommand to execute[/b]; from macaroniKazoo… :slight_smile:

before that I used a lot of lines to do the same command, which just could be on one line… :slight_smile:

regards

Alex


#9

I thought he was looking for a script to snap one object(s) “pivot point” to another objects pivot point ??? not acutal object(s) positional value snap to one objects positional value…??? ohhh well thanks for the tip tho…:applause:

Cheers,


#10

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.