Resolve add attribute when attr. name already exis

Evening folks...
In a script I need to add an attribute to a node. This node may or maynot have an attribute of the same name already.
I need the new name returned too.

addattr will not function if there is an existing attr of the same name.

lets say i want to add and attr named "homer" to a node, and an attr of that name exists, I need a return name such as "homer1" for the new attr.

is there a handy way , as usual , already in MEL, or shall I go ahead and listattrs on the destination node, then compare strings etc etc

cheeeers!

You can use the objExists command to check if that attribute exists already. Depending on how you want it to function you would use this check in an if statement to then decide what the script should be doing.

For instance...

if (objExists object.attrName)
{
// Append your attribute name with the proper numeral
}

//Add attribute of name determined in previous

If you ever want to list just the attributes that you have added use listAttr -ud.

If you are looking for an easy way, I don't have one. You will be tokenizing lots of strings, building more strings, and comparing arrays of strings.

--JeffD