View Full Version : Making a script work without separating it into multiple smaller scripts.

11-23-2011, 03:29 AM
Hey guys,

I've written a script, and it works fine If I execute each line separately.
But when I try to execute the script as a whole, I get undesired effects.
At the moment I have it split into 4 shelf buttons. But It would be awesome if it could work as one button.

Any help would be really appreciated.
I'll try and quote in descriptions so you get an idea of what I was doing.

Here's the script:

//First shelf button
// Select control group of object, copy position and rotation of object I'm replacing with a reference, delete object then import reference.
pickWalk -d up;
setKeyframe ".rx";
setKeyframe ".ry";
setKeyframe ".rz";
setKeyframe ".sx";
setKeyframe ".sy";
setKeyframe ".sz";
copyKey -t ":" -f ":" -at "rx" -at "ry" -at "rz" -at "sx" -at "sy" -at "sz";
file -r -type "mayaAscii" -namespace "tree_001" -options "v=0;p=17" "Y:/PROJECTS/P208_Habitat/Elements3D/assets/";

// Second shelf button
//First manually select a part of the freshly imported reference, select parent control group which I want to give a scale value, paste Scale and Rotation keys, set Rotate back to zero (because i was unsuccessful with pasting individual attributes)
pickWalk -d up;
pasteKey -connect true -time 1 -at "rx" -at "ry" -at "rz" -at "sx" -at "sy" -at "sz";
setAttr ".rotateZ" 0;
setAttr ".rotateX" 0;
setAttr ".rotateY" 0;

//Third shelf button
//Delete pasted keys leaving values, select parent which I want to give a rotation value, paste Scale and Rotation keys.
cutKey -cl -t ":" -f ":" -at "rx" -at "ry" -at "rz" -at "sx" -at "sy" -at "sz";
pickWalk -d up;
pasteKey -connect true -time 1 -at "rx" -at "ry" -at "rz" -at "sx" -at "sy" -at "sz";

//Fourth shelf button
//Set scale back to 1 and delete pasted keys leaving values
setAttr ".scaleZ" 1;
setAttr ".scaleX" 1;
setAttr ".scaleY" 1;
cutKey -cl -t ":" -f ":" -at "rx" -at "ry" -at "rz" -at "sx" -at "sy" -at "sz";

So, when I execute them together, here are the problems I encounter.
1. I lose the selection of the freshly imported reference, so applying attributes to it doesn't work.
2. the setAttr ".rotateZ" 0; setAttr ".rotateX" 0; setAttr ".rotateY" 0; script seems to set the scale to 0 also.

But like I said, executing the lines of script separately and in chunks seems to work.
Very confusing.

Can anyone see what I'm doing wrong?

Thanks a bunch in advance.

12-01-2011, 06:23 PM
first this pickWalk -d up is kind of crappy.

It's better i think to have your object selected, or at least do something like a recursion on listRelatives -parent if you have to go more than one step in the recursion.

then you do your copyKey
then delete

when you do your file -r, you can do something like
string $nodes[] = `file -r -type "mayaAscii" -returnNewNodes "/home/kevinsallee/dev/tests/testScenes/testExport.mb"`;

that way in nodes you get all the nodes loaded by the reference. If they're all under one common parent, pick the first node of the list, and once again a recursion on listRelatives -parent until parent is none will give you the main parent

then the rest should work

CGTalk Moderation
12-01-2011, 06:23 PM
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.