PDA

View Full Version : adding additive dynamic atribute names


nelsonteixeira
03-19-2009, 12:36 PM
I need my script to create a control curve and add an atribute named "nelson"... (it first should check if the name exists... ok... till here). But if I run the script again it should find the "nelson" attribute and create a "nelson1", "nelson2", "nelson3"... and so on. And Iīm failing on figuring this out.

If it was only a Maya object... maya would automatically rename it for me. What doesīt happen with custom attribute names.

Can anybody help??

HapG
03-19-2009, 03:36 PM
how about this:


string $node = "newCurve";
int $added;
int $append;
while(!$added)
{if( `attributeExists ("nelson"+$append) $node` )
{$append++;
}
else
{
addAttr -at "float" -ln ("nelson"+$append) $node;
break;
}
}




this above code is freehand, so there may be some syntax errors.

nelsonteixeira
03-20-2009, 10:30 AM
Thanx for the quick code... I think I can adapt the idea to solve my problem... just have to figure out a way about checking the existing attributes, because if I create a new control after running the script several times and run the script on this new control... the naming will start on "nelson7" (for example).

I added a line to show the attribute on the channel box either. Hereīs how itīs looking so far. But I didnīt have free time to get the thing done. Just wanted to thank you for the help.

string $nodes[] = `polySphere -r 1 -sx 20 -sy 20 -ax 0 1 0 -cuv 2 -ch 1` ;

int $added;
int $append;
while(!$added)
{if( `attributeExists ("nelson"+$append) $nodes[0]` )
{$append++;
}
else
{
addAttr -at "float" -ln ("nelson"+$append) $nodes[0];
setAttr -e -keyable true ($nodes[0] + "." + ("nelson"+$append));

break;
}
}

CGTalk Moderation
03-20-2009, 10:30 AM
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.