spinlock
10-11-2003, 05:26 AM
From what I've been reading I should avoid using getAttr and setAttr in expressions (as well as anything in backticks)... the problem is in my case, I don't really know what else to use.
Here's my set-up: I have an expression set up to be evaluated that simply calls a procedure that contains the real crux of the work:
$exp = "\"constraint_expression(\"" + $grp_child + "\", \"" + $child + "\");\"";
expression -s $exp -o $grp_child -ae 1 -uc all ;
// and later, the proc declaration:
global proc constraint_expression(string $grp_child, string $real_child)
{
...
}
What I'm trying to do is set up a generic proc that I can apply to multiple objects without a) duplicating code and b) having to build the entire thing as a string for feeding to the `expression ...` call.
This setup works and the expression is called correctly, but from within my proc 'constraint_expression' I'm not sure how to get and set attributes when the name of the actual object in question is passed in as a variable...
In the code that is called from the expression, I end up doing things (that work) like:
string $my_last_tran = $grp_child + ".LastTranslate";
float $last_trans[] = `getAttr $my_last_tran`;
// and...
setAttr $my_last_tran -type float3 $trans[0] $trans[1] $trans[2];
I've tried some funky things to get around using the backticks, including several variations of building a string and using 'eval' to trick maya into thinking it is a simple "$val = obj.property;" statement, but I wind up with either compile or run-time errors.
Question 1: So how do I correctly access a property of an object in an expression, when the name of the object in question is a variable?
Question 2: How do you know what Maya commands are safe to use in expressions?
Here's my set-up: I have an expression set up to be evaluated that simply calls a procedure that contains the real crux of the work:
$exp = "\"constraint_expression(\"" + $grp_child + "\", \"" + $child + "\");\"";
expression -s $exp -o $grp_child -ae 1 -uc all ;
// and later, the proc declaration:
global proc constraint_expression(string $grp_child, string $real_child)
{
...
}
What I'm trying to do is set up a generic proc that I can apply to multiple objects without a) duplicating code and b) having to build the entire thing as a string for feeding to the `expression ...` call.
This setup works and the expression is called correctly, but from within my proc 'constraint_expression' I'm not sure how to get and set attributes when the name of the actual object in question is passed in as a variable...
In the code that is called from the expression, I end up doing things (that work) like:
string $my_last_tran = $grp_child + ".LastTranslate";
float $last_trans[] = `getAttr $my_last_tran`;
// and...
setAttr $my_last_tran -type float3 $trans[0] $trans[1] $trans[2];
I've tried some funky things to get around using the backticks, including several variations of building a string and using 'eval' to trick maya into thinking it is a simple "$val = obj.property;" statement, but I wind up with either compile or run-time errors.
Question 1: So how do I correctly access a property of an object in an expression, when the name of the object in question is a variable?
Question 2: How do you know what Maya commands are safe to use in expressions?
