PDA

View Full Version : not sure how to ask this....


TheKYKid
08-10-2012, 05:06 PM
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:D = 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"
break;
case "1":
print "HANDS"
break;
case "2":
print "FEET"
break;
case "3":
print "HAT"
break;
case "4":

break;

}


Thanks!

TheKYKid
08-10-2012, 05:11 PM
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");
break;
case 1:
print ($attrName + "\n");
break;
case 2:
print ($attrName + "\n");
break;
case 3:
print ($attrName + "\n");
break;
case 4:
print ($attrName + "\n");
break;
}

TheKYKid
08-10-2012, 05:49 PM
well...I guess, it wouldn't need a switch statement right?

you'd use a match of somekind?

ldunham1
08-10-2012, 06:59 PM
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.
ie
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?

TheKYKid
08-10-2012, 08:56 PM
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.

ie...it 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.

ldunham1
08-10-2012, 10:16 PM
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?

djx
08-11-2012, 02:45 PM
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.

David

TheKYKid
08-15-2012, 07:07 PM
Hey Djx,

btw...love 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.

CGTalk Moderation
08-15-2012, 07:07 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.