Am i using setAttr wrong in my expression?

this is what i have so far for a short expression 

//r fold
$elbowRotateZ = `getAttr _bn_R_elbow01.rotate.z`;
$wristRotateZ = `getAttr _bn_R_elbow01.rotate.z`;
if(( $elbowRotateZ >= 0 || $elbowRotateZ >= -76) && ($wristRotateZ >= 0 || $wristRotateZ <= 26)) 
 
setAttr cluster2Handle.envelope = `smoothstep 0 1 (.5 )`;
 
else setAttr cluster2Handle.envelope = `smoothstep 1 0 (.5)`;

I get an error for set attr and when i take that off and even when i simply use something like:

else cluster2Handle.envelope = 0;

I still get an error.

// Error: Line 6.51: Invalid use of Maya object "cluster2Handle.envelope". // 

Can anyone let me know the issue?

edit: also  if i try to run this simpler version in expression editor:

//r fold
 
 
if(( bn_r_elbow01.rotateZ >= 0 && bn_r_wristb.rotateZ >= 0) || (bn_r_elbow01.rotateZ >= -76 && bn_r_wristB01.rotateZ <= 26)) 
 
cluster2Handle.envelope = `smoothstep 0 1 (.5 )`; 
 
 
else cluster2Handle.envelope = 0;

  i get this error for the cluster.envelope 

// Error: Attribute not found or variable missing '$':  cluster2Handle.envelope

 

setAttr cluster2Handle.envelope = smoothstep 0 1 (.5 );

Is a syntax error, you may want to bursh up on your mel knowlege. In any case using setAttr and getAttr inside a expression will make your life really miserable. Its inefficient, doesn't survive  imports, kills your undo, has no sane dirty pipe and succeeds in completely unoptimizing maya runtime of your entire scene. So im not even going bother with this one.*

cluster2Handle.envelope = smoothstep 0 1 (.5 );

is syntactically right, but most likely makes no sense for the DG. See clusterHandles don't have envelope attributes, that is unless you made one. However your error seems to indicate that no such attribute exists (yeah that's the error maya spits out, not very informative). So most likely you meant to do:

cluster2.envelope = smoothstep 0 1 (.5 );

tough normaly i would personally write:

cluster2.envelope = smoothstep(0, 1, .5 );

Off course having static values inside the expression does not make sense. So i assume theres something your not showing. (like why you have parentheses)

PS: Expressions are NOT MEL, they just execute with mostly the same rules. They are nodes so all things that applies to nodes applies to expressions. Hence they have functions that  mel does not have.

  • in essence if you dont know when youd use setAttr here thenyou would never need to