PDA

View Full Version : naming problems /auto-renaming with appended numbers


pixlix2
07-10-2007, 11:28 AM
Hello everyone,

I'm wondering whats the best way to name nodes.
I'm working on a script that creates alot of groups, I don't know how many, can't say it in advance...
If I just use the "group" command like so it will create a unique name... like "group143". But I would like to have more descriptive names, like "house143". So I tried something like:
group -n house $obj;
But this will fail if already another "house" exists.
I also tried:
string $myGroup = `group $obj`;
addPrefixToName ("house_", $myGroup);

But it does not work - no prefix appears...hmm

can anyone help me?
Many thanks!

Greetings

H3ro
07-10-2007, 01:26 PM
Add a loop to it.

Something like:

for ($i = 0; i < 10; $i++)
$name = "house" + $i

I dont remember the correct syntax for adding a number to a string, but I have solved the same problem you have like posted above.

Best of luck

pixlix2
07-10-2007, 01:46 PM
thanks for the answer... hmm, yes, that's a way it could probably be done, but there are issues. I want the script to be really stable. For example I run it once and it creates something between 200-400 objects, then i decide to delete some of them by hand and run the script again to create 50-100 more objects. I would have to loop through all objects of the scene to see which name are already given away....

maybe there is a way to get this addPrefix-thing to work?

thanks

trancor
07-11-2007, 03:51 AM
Well, you can have a list be made of all the "house" groups already existing and then start the counting from there. Enless I misunderstood something.

I realize you said you delete some objects by hand, would that mean deleting the group altogether?


string $groupList[]=`ls ("house*")`;

group -n ("house"+(size($groupList))) $obj;

Or in a loop

for ($x=size($groupList); $x<$maxVar; ++$x){
group -n ("house"+$x) $obj;
}

edit-Just a note, this wont work if you delete lets say 5 groups in the middle of the count and you still want to name them propperly because it will start counting from 5 down from the last number which would already exist.

edit edit - Err, you could always have an auto renamer in the scripting function to resituate the correct numbering.


string $groupList[]=`ls ("house*")`;

for ($x=0; $x<size($groupList); ++$x){
rename ($groupList[$x]) ("tempName"+$x);
}

group -n ("tempName"+(size($groupList))) $obj;

string $groupList[]=`ls ("tempName*")`;

for ($x=0; $x<size($groupList); ++$x){
rename ($groupList[$x]) ("house"+$x);
}


That will correct the numbering for you if you delete lets say 30 54 and 65 out of 100 numberd groups

mhovland
07-11-2007, 12:10 PM
I dont remember the correct syntax for adding a number to a string, but I have solved the same problem you have like posted above.


I believe the syntax would be "house#" to increment a number at the end of the name.

pixlix2
07-11-2007, 12:37 PM
whooohaa, so simple - it works perfectly! Many many thanks!

And also thanks for the auto renaming script, this will be helpful aswell!



Greetings

CGTalk Moderation
07-11-2007, 12:37 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.