renaming nodes

renaming nodes

slumberlander
Enthusiast Enthusiast
1,548 Views
7 Replies
Message 1 of 8

renaming nodes

slumberlander
Enthusiast
Enthusiast

 

hi there, excuse my english.

 

i m absolutely unskilled with mel/python but i m facing the circumstences where it is necessary for me to build a script for the purpose of not repeating anoying things a billion of time....

 

im making measurement of the deph of field for z deph and blur purpose.

im trying to build a camera with the mesurement tool parented to its body and aim.

the locator 1 of the mesurement tool is parented to the camera and the locator 2 to the Aim of the camera.

I build the script by drag and dropping from the shelv exactly the way i would do it in the editor, and it works!

but now:

I would like to finish the script by making it usable in any circumstances by not naming nodes by their first name:" locator1 camera1"but by

I storing nodes in variables.

but here start endless errors and nonworkings attempts...

 

here is the script:

 

 

camera;                                                 // create camera
cameraMakeNode 2 "";                          // create aim      
distanceDimension -sp 0 0 0 -ep 1 1 1; //tool
pointConstraint camera1 locator1;        //snap locator to cam
parent locator1 camera1;                     //parent it
pointConstraint camera1_aim locator2;//snap locator to aim
parent locator2 camera1_aim;              //parent it

 

how should i do? i have tried many variation with:

 

like :

 

string $myCamera =`camera`;
string $myAim=`cameraMakeNode 2""`;

it does create a camera but no aim...

Would you help me with that, or put me in the wright track for it?

 

thank you!

0 Likes
Accepted solutions (1)
1,549 Views
7 Replies
Replies (7)
Message 2 of 8

slumberlander
Enthusiast
Enthusiast

in fact i want to build a simple custom distanceDimension tool who works by selecting two objects:

 

i have tried this:

 

string $mySelection[]=`ls-sl`; 

distanceDimension -sp `getAttr $mySelection[0].translate` 
-ep `getAttr $mySelection[1].translate`  ;

I get a syntax error...

could someone give me an advise.

Thank you!

0 Likes
Message 3 of 8

mspeer
Consultant
Consultant

Hi!

 

Don't try this in one step, better:

 

string $mySelection[]=`ls-sl`;
$item1 = $mySelection[0];
getAttr $item1.translate;

 

with one step it would be:

 

string $mySelection[]=`ls-sl`;
getAttr ($mySelection[0]).translate;

You have a similar problem later in the code, it's better to split it up.

0 Likes
Message 4 of 8

slumberlander
Enthusiast
Enthusiast

hi @mspeer

 

thank you for answering,

 

there is something i can t undertstand tho...

 

if i say:

string $mySelection[]=`ls-sl`;
$item1 = $mySelection[0];
getAttr $item1.translate;

i get as result:

// Result: 0 0 0 -6.043651 -0.030879 6.066811 // 

it gives me the 6 arguments for the two translates of $mySelection[0] and $mySelection[1];

so if try to load  $item1 and $item2 in the DistanceDimention function I will give an "error while parsing arguments" because i have to much arguments i guess.

i do not understand because if i querry with a: print($item1) it will give me the name of the first object of my selection (as expected) but as soos as i getAttr it will gives me every translates in the selection....

it looks like getAttr is answering for all the membres of the array...what is wrong?

 

thank you for answering!

 

0 Likes
Message 5 of 8

mspeer
Consultant
Consultant
Accepted solution

Hi!

You are right. it needs to be changed to this:

 

string $mySelection[]=`ls-sl`;
$item1 = $mySelection[0];
getAttr ($item1 + ".translate");
Message 6 of 8

slumberlander
Enthusiast
Enthusiast

Thank you so much @mspeer,

 

for some dark reason i still have the parsing error when trying to give all 3 arguments at once...

that does not work: 

 

distanceDimension -sp `getAttr ($item1+ ".translate")` -ep `getAttr ($item2+ ".translate")`;

i have to unfold every thing as so to have it working:

 

distanceDimension -sp `getAttr ($item1+ ".translateX")``getAttr ($item1+ ".translateY")``getAttr ($item1+ ".translateZ")`-ep `getAttr ($item2+ ".translateX")``getAttr ($item2+ ".translateY")``getAttr ($item2+ ".translateZ")`;

I m curious to know what kind of syntax i m missing...

 

Anyway : thank you! 

0 Likes
Message 7 of 8

mspeer
Consultant
Consultant

Hi!

 

distanceDimension requires 3 distinct values for start point and end point not an array.

At the end this would be more elegant:

 

string $mySelection[]=`ls-sl`;
$val1 = getAttr ($mySelection[0] + ".translate");
$val2 = getAttr ($mySelection[1] + ".translate");
distanceDimension -sp $val1[0] $val1[1] $val1[2] -ep $val2[0] $val2[1] $val2[2];
Message 8 of 8

slumberlander
Enthusiast
Enthusiast
I get it! In deed it s more elegant!
0 Likes