PDA

View Full Version : cycling visibility on a set of nodes


supersteve3d
09-27-2006, 09:55 AM
Hi MELsters,

I have a project that I am helping out on. A certain part of the UI calls for the the toggling of visibility on a list of nodes.

eg.
say there are 5 nodes pSphere1 , pSphere2 ... pSphere5
I want to drive say a custom attribute to run though the list and toggle their visibility. Such that only one is visible at a time.

What is the most elegant way to do this? My gut feel is something involving using 'case' and/or 'switch' or something along those lines. Also, I am free to rename the nodes. Perhaps using numerical suffixes will make the code simpler?

Thanks for any pointers.

drGonzo
09-27-2006, 11:02 AM
If I understand you correctly, a simple loop will do:


string $sel[] = `ls -sl`;
for ($each in $sel)
setAttr ($each + ".visibility") 0;


If you want to do the selectin based on a name, you could replace the first line with this:
string $objs[] = `ls -tr "pSphe*"`;

supersteve3d
09-28-2006, 01:56 AM
Thanks Gonzo,

The code you have is useful. However..

I am not sure if I should be using expressions or MEL. Your code is in MEL.

Here is the brute force approach to using expressions to toggle vis in of a list of nodes from a custom attribute..

if (head_ctrl.head_angle == 0)
{

head_side_L.visibility = 1 ;
head_34_L.visibility = 0 ;
head_front.visibility = 0 ;
head_34_R.visibility = 0 ;
head_side_R.visibility = 0 ;
head_side_scream_L.visibility = 0 ;
head_side_scream_R.visibility = 0 ;
}
else if (head_ctrl.head_angle == 1)
{
head_side_L.visibility = 0 ;
head_34_L.visibility = 1 ;
head_front.visibility = 0 ;
head_34_R.visibility = 0 ;
head_side_R.visibility = 0 ;
head_side_scream_L.visibility = 0 ;
head_side_scream_R.visibility = 0 ;
}

Thing is, it works but its very crude.
I think the best way is to do the following..

1. Turn off all the nodes (initialize)
2. Turn on the corresponding node (eg. pSphere1) when the custom attribute = 1

Firstly I am trying to rewrite your 3 lines from MEL into Expression syntax. From what I've read, it has to be direct access ie. no setAttr are used etc.

Secondly, I am looking into a better way to do the conditions than just if..else. Hence my initial post about switch and case etc.

Lastly, what do you guys think about the use of expressions? Are all custom attributes driving expressions? Can you tie them to MEL scripts? Would you want to? :)

Thanks for the insight.



PS. How is camilla? :)

supersteve3d
09-28-2006, 08:26 AM
The plot thickens..

I have shortened the code considerably. It works great and can be reused for different sets of targets and different custom attribute names.. Here is the code.


string $targetName = "pSphere";
string $attrName = "supervis";

tglVis(Control.supervis);

proc tglVis(int $count){
string $objs[] = `ls -tr ($targetName+"*")`;
addAttr -e -maxValue `max 1.0 (size($objs))` ("." +$attrName); dynRenameUpdateMinMax ("."+ $attrName);
for ($each in $objs)
{setAttr ($each + ".visibility") 0;}
setAttr ($targetName + $count + ".visibility") 1;
}


What is weird is that you have to move the timeline in order for the procedure to run. What is more strange, is that you can get around this by assigning a value to an attribute. eg. test.dummy = 0

The problem is that attribute becomes locked. If you use this code again somewhere else, you need another 'holder' attribute to set in order to make the expression 'refresh/realtime'.

I have also uncovered some other strange quirks and inconsistencies that I will post in another thread.

Any input is appreciated.

Thanks.

mexxmillion
09-29-2006, 03:17 PM
hi steve..

ur case will be easier to use utility nodes.. as they are superfast compare to ur expressions.. also.. using setAttr and getAttr in expressions are very slow..

i just use condition nodes to control the spheres visibility.. u can drive that attr with anything .. just an example.. see my attached file..

the counter attr in locator1 control the viz of 3 spheres.. use 0,1,2 values..
u can script it to make such networks pretty fast.

CGTalk Moderation
09-29-2006, 03:17 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.