PDA

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


Javiideas
06-22-2012, 04: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!

Javiideas
06-23-2012, 12:06 PM
come on! a little help would be nice, please!

djx
06-23-2012, 03: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.

david

Javiideas
06-23-2012, 11: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:
http://download.autodesk.com/us/maya/2011help/Commands/scriptJob.html
http://www.youtube.com/watch?feature=endscreen&NR=1&v=IuWbn4zQPDM



-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?

djx
06-24-2012, 03: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"

David

Javiideas
06-24-2012, 12:22 PM
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.

site:download.autodesk.com/global/docs/maya2012/en_us/ -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.

djx
06-24-2012, 02: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)

David

Javiideas
06-24-2012, 07:16 PM
Great News! atributteChange send me to a loop on the Script Editor..so 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!

tontonsuspect
06-24-2012, 11: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...: http://circecharacterworks.files.wordpress.com/2012/06/toggle.pdf ( rename ".pdf" by ".zip" and extract in a registred maya plugins folder)

loadPlugin toggle.py;
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 )

Javiideas
06-25-2012, 12:13 AM
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) ?

tontonsuspect
06-25-2012, 12:54 AM
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

http://circecharacterworks.files.wordpress.com/2012/06/toggle_ui.png
I though that you wanted mutual exclusion and as a node writer I do it with ...( wait for it... ) node.

loadPlugin toggle.py; 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 )

djx
06-25-2012, 02: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() {
reset("nurbsCircle1");
}
global proc reset2() {
reset("nurbsCircle2");
}
global proc reset3() {
reset("nurbsCircle3");
}
global proc reset4() {
reset("nurbsCircle4");
}

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

david

tontonsuspect
06-25-2012, 03:14 PM
thanks david, the most obvious use could be for space switching or visibility toggle

Javiideas
08-17-2012, 05: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!

vimeo.com/javiideas/donrutino

CGTalk Moderation
08-17-2012, 05: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.