not sure how to ask this....

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Search this Thread Display Modes
Old 08 August 2012   #1
Post not sure how to ask this....

Hi there,
sorry not sure if there's a better way to ask this...
I think this would be a pretty common procedure...I just dont know what it would be called or how to go about it.
so if there is, any help is greatly appreciated.

Is it possible to query an object with an enum attribute,
get the size of the enum attribute ( how many different options ie. A:B:C = 4)
then build a switch with the same number of "case" es , then spit out the name for each one.
So if it the attribute enum int value is 0 it can also read that its "HEAD" or whatever it may be...
at the moment, I can make the switch statement, but what if the enum changes on the next object, and it has different choices?

  for ($sel in $sels)
  string $attrName =  `getAttr -as ($sel + ".tag")`;
  string $attrNum =  `getAttr  ($sel + ".tag")`;
  switch($attrNum )
  case "0":
    print "HEAD"
  case "1":
   print "HANDS"
  case "2":
   print "FEET"
  case "3":
   print "HAT"
  case "4":

Old 08 August 2012   #2
actually, just figured out the part of how to give the name for the number...

I still would like to know how to create the case count by querying the attribute

   for ($sel in $sels)
 string $attrName =  `getAttr -as ($sel + ".tag")`;   
 int $attrNum =  `getAttr  ($sel + ".tag")`;
  switch($attrNum )   {   
 case 0: 
      print ($attrName + "\n");
  case 1:
  print ($attrName + "\n"); 
 case 2:
  print ($attrName + "\n");    	
  case 3:
  print ($attrName + "\n");
   case 4: 
       print ($attrName + "\n");       
Old 08 August 2012   #3
well...I guess, it wouldn't need a switch statement right?

you'd use a match of somekind?
Old 08 August 2012   #4
if your attrs will expect same return value across the board and the $attrNum var is an int then you can simply use an array and query the value using the $attrNum as the index number.
string $valueArray[] = {"zero","one","two","three"} ;

for ($sel in $sels)
 string $attrName =  `getAttr -as ($sel + ".tag")`;   
 int $attrNum =  `getAttr  ($sel + ".tag")`;
  print $valueArray[$attrNum] ;

does that help?
Old 08 August 2012   #5
Thanks Lee for your quick response!

the steps that follow the what is read from the .tag attr will be dependent on what the value is. wont be as simple as making a group with that name but more like if its "A" then make a cube, if its "B" then dance a jig

I'm not sure if your code would help in that situation.
Old 08 August 2012   #6
hmm im not too sure, there are workarounds but im not 100% on the final outcome your after. What i can suggest would be python if its available to use in your situation?
Old 08 August 2012   #7
Hey TheKYKid, I dont understand why you want to make your switch have the same number of cases as you object has enum items. Surely your switch just needs to respond to any of the possible enum item names.

So you would just need to `getAttr -as`, and then switch based on $attrName. If every object has different enum strings, just add them all as cases.

Old 08 August 2012   #8
Hey Djx, your site...great resource! seriously...I'm referencing it all the time.

well, I've got it figured out to the point that it works..may not be pretty...but it works.

I basically did your suggestion. But the reason for my question was to make it a more usable script later to make it usable for multiple situations.

in the event that I add more or different enum choices. I guess I can just adapt the script later on.
Old 08 August 2012   #9
Thread automatically closed

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.
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 07:06 PM.

Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.