View Full Version : How to this Expression: when turn-on one control the others (13 controls) turn-off

06 June 2012, 03:07 PM
Hi everyone,
i have 14 blendshapes, each one related to a control (a nurbscircle with limit translation in Z and X) so when i move in Y axis down the blendshape turn-on, and when i move in Y axis up the blendshape turn-off.

How can i tell to maya that when i turn-on One of the 14 controls i want that the others 13 control turn-off, to each control?

I tried with set driven keys and expression if and even but i dont know enough expression language for this. Thanks in advance!

06 June 2012, 11:06 AM
come on! a little help would be nice, please!

06 June 2012, 02:11 PM
You could have 14 scriptJobs, each one triggered by 1 of the 14 ty attributes. The script job would set the other 13 ty's to the up-value if this ty is not the up-value.


06 June 2012, 10:14 PM
THANK you david! thats exactly what i want. I have no idea how write the scriptjob yet, but i found some useful links:

-How can i set a condition? i mean, if a use conditionTrue...i write "conditionTrue= 3,54" or "conditionTrue=positionX"...?
-Some book, tutorial or website with essentials resources for a newbie evolved in this task?

06 June 2012, 02:34 AM
I would use -attributeChange (not -conditionTrue). Have a look at the examples on the scriptJob page in the maya docs. There is an example where they use -attributeChange to monitor the ty attribute and print a warning if ty > 10. You could do something similar.

Based on you first post it sounds like you want all other ctrls to be set back to 0 if one is moved down (to -1 maybe). So you need to write a mel script (maybe call it "resetCtrls") to check which ctrl is selected. Then getAttr to find the ty value. If ty not equal to 0 then, for the other 13 ctrls, do setAttr to set their ty=0.

Then create 14 scriptJobs to monitor each of the the ty attributes using something like "-attributeChange ctrl1.ty resetCtrls"


06 June 2012, 11:22 AM
but Autodesk Maya help says:

They do not work in batch mode or prompt mode. They are meant to be used to customize your user interface. Don’t try to use them to make things happen during the running of an animation, because they will not execute during playback or batch rendering. Use expressions instead. -attributeChange

This mean that i wouldnt animate the ctrls?

The main, may the only, purpose of this is that can easier animate the pass from one pose to another, with all the blendshapes.

Thanks, started with some exercises, but no with animation yet.

06 June 2012, 01:31 PM
Yes, you can animate the controls but you must key them. Using auto-key is probably advisable (though not essential). The idea of the script job hook up is that it saves you having to manually reset the other 13 controls when you drag one of them into a non-zero position. (At least thats what I thought you were asking in your first post) If you use auto-key, no problem. If you dont like auto-key, you need to remember to do it yourself or the other 13 will just jump back as soon as you change frames.

Once you get the scripting worked out it would not be difficult to have a shelf button that would create the whole set up for you. This way the script jobs can be temporary and only created as you need them, and deleted after (or when you exit the scene maybe - you have options to choose here)


06 June 2012, 06:16 PM
Great News! atributteChange send me to a loop on the Script i figured out another way... :lightbulb i made a custom window with 14 buttons, each one to one pose (and each one even with his own image!). Next i created a global procedure to each pose who fires his blendshapes (the poseA has all blendshapes = 0, the pose B has blendshapeEyebrow = 0, blendshapeMoustache = 1,...). Thats it.

And if i want to key something, just click the pose i want and then click KEY ALL. I tested two poses and works fine! so tomorrow iŽll put a screencapture video with everything. btw, Thanks again David!

06 June 2012, 10:30 PM
Hello everyOne, just my two cents: how about a really stupid python scripted plugin that act as multi output choice node? shameless plug...: ( rename ".pdf" by ".zip" and extract in a registred maya plugins folder)

createNode toggle;

when you change your count attribute and you have nothing connected to this node don't forget to invoke
getAttr yourToggleName.outState;

It will grow and shrink the number of element in the outputArray attribute outState then you will be able to use the connection editor with the correct number of element.

( dont get too focused on my messy code, tell me if it works on your side )

06 June 2012, 11:13 PM
hi tontonsuspect, thanks to join us! but i mut say that i didnt understood what is the purpose of your script, and how to load it, well, i dont so much scripting, could you extense a little more in your explanation?and what is the advantage comparing to my method (see message before yours) ?

06 June 2012, 11:54 PM
From your first question :
How can i tell to maya that when i turn-on One of the 14 controls i want that the others 13 control turn-off, to each control?

This is a custom maya node ( written with the maya python API hence scripted plugin...) that just write all output to off then turn the active index to 1
I though that you wanted mutual exclusion and as a node writer I do it with ...( wait for it... ) node.

loadPlugin; is a mel command and will load this plugin

createNode toggle; create this type of node ( by now you can see these command are self explanatory )

06 June 2012, 01:41 PM
Hey tontonsuspect, I like the look of that toggle node. That could save quite a few nodes in many rigging situations I would imagine.

Javiideas, sounds like you have a solution already, but just in case you ever wanted to revisit the scriptJob approach, I put this example together. Assumes you have 4 nurbs circles moving up and down the y axis, where zero is the reset value.

global proc reset(string $nc){
string $ctl[] = {"nurbsCircle1", "nurbsCircle2", "nurbsCircle3", "nurbsCircle4"};
string $sel[] = `ls -sl`;
if($sel[0] == $nc) {
float $y = `getAttr ($sel[0] +".ty")`;
if ( $y > 0.0 ){
for ($c in $ctl) {
if($c != $nc) {
float $yy = `getAttr ($c + ".ty")`;
if($yy != 0) {
print ("Reset " + $c + "\n");
setAttr ($c + ".ty") 0;
global proc reset1() {
global proc reset2() {
global proc reset3() {
global proc reset4() {

scriptJob -attributeChange nurbsCircle1.ty reset1;
scriptJob -attributeChange nurbsCircle2.ty reset2;
scriptJob -attributeChange nurbsCircle3.ty reset3;
scriptJob -attributeChange nurbsCircle4.ty reset4;


06 June 2012, 02:14 PM
thanks david, the most obvious use could be for space switching or visibility toggle

08 August 2012, 04:29 PM
Hi guys, I found how turnOn/turnOff 14 controls, so I finished my shortfilm and you can see a little Breakdown at the end. I created a script job with a window and custom icons! hope you like it and enjoy the shortfilm!

CGTalk Moderation
08 August 2012, 04:29 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.