View Full Version : How to have if statement driven by attribute change

02 February 2011, 01:32 AM
I've got a script I'm trying to have driven by an attribute change. But when I use an if statement, it locks the attribute to the value I'm trying to use to drive the expression.

Here's my code. Does somebody else have a better way of doing this?

if (Tail1_CTRL.controls = 0.25)
setAttr Tail2_CTRL.rx 0;
setAttr Tail4_CTRL.rx 0;
setAttr Tail6_CTRL.rx 0;
setAttr Tail8_CTRL.rx 0;
setAttr Tail2_CTRL.ry 0;
setAttr Tail4_CTRL.ry 0;
setAttr Tail6_CTRL.ry 0;
setAttr Tail8_CTRL.ry 0;
setAttr Tail2_CTRL.rz 0;
setAttr Tail4_CTRL.rz 0;
setAttr Tail6_CTRL.rz 0;
setAttr Tail8_CTRL.rz 0;

if (Tail1_CTRL.controls = 1)
float $tail2RotX = `getAttr Tail2_rotGRP.rx`;
float $tail2RotY = `getAttr Tail2_rotGRP.ry`;
float $tail2RotZ = `getAttr Tail2_rotGRP.rz`;

float $tail4RotX = `getAttr Tail4_rotGRP.rx`;
float $tail4RotY = `getAttr Tail4_rotGRP.ry`;
float $tail4RotZ = `getAttr Tail4_rotGRP.rz`;

float $tail6RotX = `getAttr Tail6_rotGRP.rx`;
float $tail6RotY = `getAttr Tail6_rotGRP.ry`;
float $tail6RotZ = `getAttr Tail6_rotGRP.rz`;

float $tail8RotX = `getAttr Tail8_rotGRP.rx`;
float $tail8RotY = `getAttr Tail8_rotGRP.ry`;
float $tail8RotZ = `getAttr Tail8_rotGRP.rz`;

if (Tail1_CTRL.controls = 0.75)
setAttr Tail2_CTRL.rx $tail2RotX;
setAttr Tail2_CTRL.ry $tail2RotY;
setAttr Tail2_CTRL.rz $tail2RotZ;

setAttr Tail4_CTRL.rx $tail4RotX;
setAttr Tail4_CTRL.ry $tail4RotY;
setAttr Tail4_CTRL.rz $tail4RotZ;

setAttr Tail6_CTRL.rx $tail6RotX;
setAttr Tail6_CTRL.ry $tail6RotY;
setAttr Tail6_CTRL.rz $tail6RotZ;

setAttr Tail8_CTRL.rx $tail8RotX;
setAttr Tail8_CTRL.ry $tail8RotY;
setAttr Tail8_CTRL.rz $tail8RotZ;

02 February 2011, 11:55 AM
your syntax is wrong:
if (Tail1_CTRL.controls == 1)using a single = SETS the variable to the value!
also, variables defined inside a {scoped block} do not exist outside of that block, so all your floats may not be useable in the third block..?
However, you should avoid using setAttr and getAttr in an expression, you should probably just be connecting these attrs together via a utility node of some kind which controls the behaviour your if's are trying to achieve..? Although I'm not too sure tbh as I can't work out exactly what it is you're doing, and how... :)


02 February 2011, 05:12 PM
I'm using it to simplify some tail controls. On the tail every other control becomes an average of the two around it and is hidden until you turn them on. If they want more fidelity, those in-between controls turn on, and take the average rotation values from it's parent node, zeros out the parent node and applies them to the control for the animator to use. I can drive the parent node with utility nodes, but I can't drive the controller because I need it free for the animators. Going back, we just set the control back to 0 and hook the parent back up to the average. (there's an average node hooked up to a blend node, where the other color is 0.)

I haven't been needing scripting as much lately and had forgotten about ==, so thanks for that. If you have any better idea for the control system, I'd love to hear it. I was thinking ik spline at first with just 4 controls rather than a total of nine, but I didn't think that was as condusive for the floppy animation they need to make.

CGTalk Moderation
02 February 2011, 05:12 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.