View Full Version : Difference between ` and eval()?
12-31-2007, 11:29 PM
The following code evaluates fine:
float $joint1RotY = (`getAttr -t (frame-2) amberJackMainNode.rotateY`);
Obviously, it pulls the value from amberJackMainNode.rotateY two frames ago. Problem is, I want to be able vary the frame that $joint1RotY gets it's frame from based on another attribute. Ideally, I'd run it like:
float $joint1RotY = eval("getAttr -t (frame-"+$attribute+") amberJackMainNode.rotateY");
Problem is, eval doesn't seem to want to let me use frame. It errors with:
// Error: } //
// Error: Line 0.18: Invalid use of Maya object "frame". //
// Error: line 0: An execution error occured in the expression expression2. //
12-31-2007, 11:59 PM
eval is usually used when you are building the command dynamically and then calling it
for your example you dont really need to use the eval command
float $joint1RotY = (`getAttr -t ( frame - $value) amberJackMainNode.rotateY`);
should work, alternatively you can use `currentTime -q` instead of "frame"
$offsetValue = (`currentTime -q` - $value);
let me know if that helps, but if anyone knows a more correct explanation I'd like to hear it too
01-02-2008, 09:46 AM
"frame"?!?! Whats that? I just get:
// Error: Line 1.40: Invalid use of Maya object "frame". //
Do you have a custom proc called "frame"? If you initialized it locally not global eval can not find it because eval always works global! But even in that case: "frame" just creates an error! Instead: frame() works!
Is "frame" a Maya 2008 feature? I still work on 7.0.
You don't need eval to put in a variable:
proc float frame()
return `currentTime -q`;
float $anothoerVariable = 4;
float $joint1RotY = (`getAttr -t (frame() - $anothoerVariable) pCube1.rotateY`);
print("$joint1RotY: " + $joint1RotY + "\n");
01-02-2008, 02:18 PM
is an undocumentedish hack in maya. If you have an attribute in Maya you can type in frame in it and it'll assume the value of the current frame. Works well for image sequences.
I dont think it'll work in a script though.
01-02-2008, 02:33 PM
mhh -I was thinking, that "frame" works just in expressions. I will have a try...
Thanks for this tipp
01-02-2008, 02:57 PM
frame is a variable only available in expressions. If you use ` you are requesting the return value from a command. If you use eval, you are running an entire script in a seperate scope from the place where it is called. A simple demonstration of this would be:
This will work, since $a is in scope.
This will fail because $a is not in the same scope as the script being executed in eval.
eval( "print $a" );
The use of ` basically allows you to grab some return arg without using brackets, for example:
$color = `getAttr "lambert1.color"`;
However, will all mel commands, you can also use brackets if needed....
$color = getAttr("lambert1.color");
and another example with using a command flag.....
$objects = ls("-type","lambert");
01-02-2008, 02:57 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.
vBulletin v3.0.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.