PDA

View Full Version : EXPRESSIONS: toggling on/off visible attribues


chewman
09-19-2004, 07:32 AM
Hey peoples,
I'm in need of some help here. I've got several attributes attached to an object. What I want is when you enter a value of 1 into one of the attributes, some other attributes are then turned off and left non keyable, then when you enter in 0, those values are keyable and therefore visible.
So what I've done is selected my object, opened up the expression editor and selcted the 'by object/attribute name' filter then typed in the expression:

if (MT_4WDcontroller.awdOn == "off" || MT_4WDcontroller.awdOn == 0) {
setAttr -lock true "MT_4WDcontroller.allWheelSpin";
setAttr -lock false "MT_4WDcontroller.frontWheelSpin";
setAttr -lock false "MT_4WDcontroller.rearWheelSpin";
} else if (MT_4WDcontroller.awdOn == "on" || MT_4WDcontroller.awdOn == 1) {
setAttr -lock false "MT_4WDcontroller.allWheelSpin";
setAttr -lock true "MT_4WDcontroller.frontWheelSpin";
setAttr -lock true "MT_4WDcontroller.rearWheelSpin";
}

After that I pressed the 'create' button.
Then on my value which I wanted to toggle on and off.. I typed in 1 (for on) and it locked the value that I wanted, great. So I type in 0 (for off) but it doesn't unlock the the attribute and it doesn't lock the other attributes either.

I don't know how to get around this seeminly easy problem. if ANYONE can help. it'd be MUCH appreciated!

chewman
09-19-2004, 12:48 PM
Ok I've just found that that the expression was working, but that an expression calculates per frame.. so i wouldn't see the changes updated unless I moved to another frame.

So now my new question is... is there a way to have an expression recalculate itself regardless of a frame?

wrend
09-20-2004, 03:40 AM
just make, say, MT_4WDcontroller.v = 1 somewhere in the expression, and evaluation will be pulled. you dont need to check for both off/on and 0/1, they are equivalent.

chewman
09-20-2004, 04:18 AM
SWEET!!! thank you heaps! does it work because its actually setting a value of an attribute rather than just affecting the attributes' property? either way I'm happy that it works!

cheers mate, thank you very much.

wrend
09-20-2004, 01:37 PM
no problem. :) yuh, beause an outgoing = creates a dependency on the expression, it causes it to re-evaluate when its incoming(s) change. s/getAttrs dont gnerate dependencies.

chewman
09-21-2004, 01:06 AM
aaah ok, makes sense ey!

I just tried it with a different setting though, using -keyable false/true, stil using the whatever.v = 1, but this time it didn't seem to calc the expression or recalculate it rather.

Not that it's important, but would you know what's going on there? why would -lock work and -keyable wouldn't work?

wrend
09-21-2004, 01:46 PM
mm, that'd be an issue with the channelBox rebuilding during interaction. you'd find it'd be as you expect after flipping to the attribute editor or changing selection off and back to it. you could evalDeffer it to get it updating then and there.

chewman
09-21-2004, 02:29 PM
ah ok. I'll give the evalDeffer a go then.
cheers mate.

CaptainSam
09-21-2004, 02:53 PM
Theres not really any point in using an expression for something that simple. Use a condition node, which will do the same thing, but evaluates faster and has no time update issues

chewman
09-21-2004, 03:47 PM
Theres not really any point in using an expression for something that simple. Use a condition node, which will do the same thing, but evaluates faster and has no time update issues
oh ok. I'm REALLY new to all of this stuff, expressions/MEL etc.. so I really don't know what a condition node is.. but I was reading up on it and it said its something to do with colours? Obviously since Maya is node based, then you can simply plug things into each other.. but would be able to elaborate a bit on how I would use the condition node?

tsdorsey
09-22-2004, 10:36 PM
Not trying to step on your toes CaptainSam but...

The condition node is fairly simple. It has...

Input 1
Input 2
How to compare those inputs
Output RGB if condition true
Output RGB if condition false

you could plug you two numbers into Input 1 and 2 thats easy enough. Then use the the output of just One of the color attributes (like the "red") to drive the "keyable" attribute of the other nodes. It would all be in the connection editor and you can look at your connected nodes in the hypergraph to get a visual representation of what is happening.

So you could set it up so that

input 1 is comming from MT_4WDcontroller.awdOn
input 2 is set to one
condition is set to "equal"
Output if true is set to 1 0 0
output if fasle is set to 0 1 0

now you can plug the "R" and "G" output into the right attributes and have it all node based

Any questions, just ask!
Trevor

chewman
09-25-2004, 06:37 AM
Hey Trev,
thanks heaps for that! I knew you could plug things into each other but had no idea how to do it. It's cool to have it all node based so that, as you said, you can see it all in the hypergraph and know what's going where.

cheers!

CGTalk Moderation
01-19-2006, 07: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.