View Full Version : Renaming

07 July 2007, 08:59 AM

I've seen this done in external tools, but I don't know how to do it in the script itself.
How would I rename things in a hierarchy so that they follow the same naming convention?
Would anyone have a small piece of code so I could see how this is done?


07 July 2007, 04:24 PM
Hearing that, it sounded interesting so I decided to write my own version. True it's like a 10 minute write up and it's pretty basic but for your sake I'll put it up now. I'm figureing I'd make a check to see if you have a parent or child selected and run through checking if you selected a random parent in middle of a tree or not. Right now this works if you select the base child object and run it -


string $selectedList[]=`ls -sl`;
string $relative[];
string $renamed;
int $i=0;

for ($x=0;$x<1;++$i){
if($i == 0){
$relative=`listRelatives -p $selectedList[0]`;
}else if($relative[0] != ""){
$relative=`listRelatives -p $renamed`;
}else if($relative[0] == ""){
//Designates the breaking of the for loop

//Checks if there is a parent and renames
if($relative[0] != ""){
rename $relative[0] ($prefix+($i+1));
$renamed = ($prefix+($i+1));


I used the listRelatives command, if you notice in the lines
$relative=`listRelatives -p $selectedList[0]`;
$relative=`listRelatives -p $renamed`;

That -p means parent, if you change that to -c and select a the main parent of a tree it will work as well, checking for children rather than parents.

The prefix name is used and from child up it is numbered 1 2 3 4 and so on, so the head grand/great grand/ great great WHAT EVER parent will have a number of 5 6 7 or what ever it is.

I made a list of the objects selected, it would be easy to put this script into a for loop and have multiple children's parents get renamed.

Hope this can provide some insight for you.

CGTalk Moderation
07 July 2007, 04:24 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.