PDA

View Full Version : Expressions: How to avoid setAttr when...


prettyh8machine
01-10-2004, 11:35 AM
Hi,
How to avoid setAttr command in a dynamic expression in this scenario: (I know using setAttr is not recommended in an expression)

setAttr ("object" + (particleId+1) + ".attribute") 10;

Ideally it should have been

("object" + (particleId+1) + ".attribute) = 10;

but naturally in this case Maya would try to assign a float/int to a string on the left side which isnt allowed. I tried a lot of tricks but I couldnt do anything when you have some sort of variable in "object.attribute" statement.

Any help ?

brubin
01-12-2004, 09:36 PM
Originally posted by prettyh8machine
Hi,
How to avoid setAttr command in a dynamic expression in this scenario: (I know using setAttr is not recommended in an expression)
WHY?


...

Any help ?

i created a simple scene with 3 regular spheres.
i want the selected sphere to bounce up and down while i'm playing back
so i created this expression:
>
string $aSels[]; $aSels = `ls -sl` ;
string $sel = $aSels[0] ;
string $atr ; $atr = ($sel+".ty") ;
setAttr $atr `sin(time)` ;
<
create that with any name and hit play. make sure there's always one object selected. et voila!

does that help? i'm not sure whether your question is 100% clear... and i don't understand your concern, really...

HIH
s.

prettyh8machine
01-19-2004, 12:47 PM
Its clearly written everywhere that setAttr in a dynamic expression can cause abnormal behavior. Also you get cycleCheck warning etc. so using setAttr in a per particle dyanamic expression is out of question (atleast should be avoided). So now the concern really is:
how to use "object.attribute = something" instead of "setAttr object.attribute something" when object is a variable ??

In your example, maya evaluates setAttr by taking its arguments as strings while in a dynamic epxression, it expects the left hand side of the .attribute to be a valid object instead of a string since its no MEL, so you get the point.

Any help

macaroniKazoo
01-19-2004, 09:31 PM
the expression sytax for setAttr is simply:

pCube.rotation = 10;

for your example, you look like you're trying to iterate over all particles, and set a PP attrib... well, particle expression automatically iterate over all particles.

ie, if you had the creation expression:

particleShape.colorR = rand(0,1);

(i'm not too sure about the attrib name, but the syntax is pretty much right...) then it will automatically be applied separately to each particle in the shape node.

to create a particle expression (slightly different from a normal expression), just right click on one of the attribs in the attrib editor for the particle shape node.

CGTalk Moderation
01-17-2006, 03:00 AM
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.