Parent, Zero Out Transforms, Unparent

Parent, Zero Out Transforms, Unparent

peter_baehr97
Contributor Contributor
1,756 Views
2 Replies
Message 1 of 3

Parent, Zero Out Transforms, Unparent

peter_baehr97
Contributor
Contributor

Hey Guys,

 

Im VERY new to MEL-Scripting and I'm trying to do the following in a script:

 

Before the script:

1. select 1 Object (object1)

2. select a second Object (object2)

 

The Script:

1.Parent object1  to object2 (so object2 is the parent of object1)

2. Zero Out Transforms (translate+rotate) of object2

3. Unparent object2

 

My Problem: Parenting and unparenting seems to be working correctly. But my script also sets the values of the Parent to 0, but i only want to set the values of the originally second selected object to 0.

Here is the exact Script I am using:

{

string $nodes[] = `ls -selection`;

parent;

select ($nodes [1])



    int $rX = getAttr ($node[1] + ".rotateX")`;
    int $rY = getAttr ($node[1] + ".rotateY")`;
    int $rZ = getAttr ($node[1] + ".rotateZ")`;
	int $tX = getAttr ($node[1] + ".translateX")`;
    int $tY = getAttr ($node[1] + ".translateY")`;
    int $tZ = getAttr ($node[1] + ".translateZ")`;
    setAttr ($node[1] + ".rotateX") ($rX = 0);
    setAttr ($node[1] + ".rotateY") ($rY = 0);
    setAttr ($node[1] + ".rotateZ") ($rZ = 0);
	setAttr ($node[1] + ".translateX") ($tX = 0);
    setAttr ($node[1] + ".translateY") ($tY = 0);
    setAttr ($node[1] + ".translateZ") ($tZ = 0);


parent -w;
}

 

0 Likes
Accepted solutions (1)
1,757 Views
2 Replies
Replies (2)
Message 2 of 3

mspeer
Consultant
Consultant
Accepted solution

Hi!

It's not clear from your description and your code what you want to do exactly, but it seems you want to move one object to the same position of the other object.

In this case simply try

 

 

matchTransform

 

 

 

Your code also has many error, so if you still want to use this try as starting point:

 

 

{
string $nodes[] = `ls -selection`;

parent;

setAttr ($nodes[0] + ".rotateX") ($rX = 0);
setAttr ($nodes[0] + ".rotateY") ($rY = 0);
setAttr ($nodes[0] + ".rotateZ") ($rZ = 0);
setAttr ($nodes[0] + ".translateX") ($tX = 0);
setAttr ($nodes[0] + ".translateY") ($tY = 0);
setAttr ($nodes[0] + ".translateZ") ($tZ = 0);

parent -w $nodes[0];
}

 

 

or

 

 

{
string $nodes[] = `ls -selection`;

parent;

setAttr ($nodes[1] + ".rotateX") ($rX = 0);
setAttr ($nodes[1] + ".rotateY") ($rY = 0);
setAttr ($nodes[1] + ".rotateZ") ($rZ = 0);
setAttr ($nodes[1] + ".translateX") ($tX = 0);
setAttr ($nodes[1] + ".translateY") ($tY = 0);
setAttr ($nodes[1] + ".translateZ") ($tZ = 0);

parent -w $nodes[0];
}

 

 

based on the object transforms you want to zero out.

Message 3 of 3

peter_baehr97
Contributor
Contributor

Thanks for the quick response! I actually didnt even execute the script that i posted above. I am very lost right now in the Scripting environment of Maya. But you helped me doing my first steps! BIG THANKS.

0 Likes