PDA

View Full Version : problem of renaming - 2 same name in a scene


ctb
10-23-2006, 07:49 AM
Hi,

I have a simple rename script:

string $sel[] = `ls -sl`;
int $size = `size($sel)`;
int $i;
for($i=0; $i<$size+1; $i++)
{
rename $sel[$i] ("new" + ($i+1));
}

It works fine when dealing with nodes in different names.

If same name appear in a scene. The scirpt will give me error:
For example:
I create joint1, joint2, joint3 and joint4.
I duplicate the joint1, so the outliner looks like the following pic.

I select joint1, joint2, joint3, joint4 to rename.
The joint1 is renamed as new1
The script stop renaming at joint2 & give me an error:
// Error: No object matches name //

Does anyone know how to solve this problem??

Many many thanks in advance.

Thanks you....

Visual_E
10-23-2006, 08:08 AM
try a decreasing iteration instead:

for($i=$size-1; $i>=0; $i--)

arunspooja
10-23-2006, 09:28 AM
Hai friends,

In ur script, ur renaming the parent joint first and then attempting to rename the child joints.

since the selected joints are stored in the array with the path.

for eg. $sel[0]="joint1"
$sel[1]="joint1|joint2"
$sel[2]="joint1|joint2|joint3"

In this ur renaming the "joint1" name, so you cant access the other joints, as the path is changed "new1|joint2".

If u rename from child there will be no errors.

try this:

string $sel[] = `ls -sl`;
int $size = `size($sel)`;

int $i;

int $k=$size;

for($i=$size-1; $i>=0; $i--)

{

rename $sel[$i] ("new" +$k);

$k=$k-1;

}

Adam
10-24-2006, 05:25 AM
Maybe Im not getting what you are asking but you could simply add the -l (longname) to the ls command. This makes it so even objects with the same name actaully have differnt names by tracing out the name through its hiegharchy. It is a good idea to almost always use the -l flag with list as it resolves this often problem. Here is your code altered.... I also altered your for loop a bit as I think it is a little to complicated and deleted stuff you dont need.

string $selList[] = `ls -l -sl`;
$k = 1;
for($sel in $selList)
{
rename $sel ("new" + $k);
$k++;
}

hope this helps

ctb
10-25-2006, 10:23 AM
Thanks guys...

I had tried these scripts which you guys suggested here..
VisualE & arunspooja 's script works fine if I start select from joint1 , follow by joint2, joint3, joint4.
Adam'sscript works if I start select from joint4, follow by joint3, joint2, joint1.

I think I should explain what I need here...
I am creating a simple GUI that renaming any things in a scene.
I'm looking at a flexible way to select any object in a scene randomly or orderly for renaming.
I have problem with renaming object in same name.
If I use VisualE/ arunspooja's script, I know the order that selecting joint1 first, later by joint2, joint3 & joint4.
If my colleague using this simple renaming script, he/she may not know the order (select joint1 first, later by joint2, joint3 & joint4). He/she might select joint4 first, follow by joint3, joint2, joint1. Then, error pops up.

So, does anyone have any idea how to solve this out (a flexible way to select objects for renaming, even for the those objects with same name)?

Thanks guys..
I hope I make myself clear here...

cheers.

kwood
10-25-2006, 06:46 PM
This will changed based on how you pass in your information and you will need to get kind of fancy with the way you move data around your arrays and loops. You will probably want to use a do while loop so you can kill it and keep it running till you have itterated as many times as you need to.

If you want the user to be able to select things in any order then you are going to need to update your arrays or strings after an object is renamed.

You are going to need to do some string fixing after each object is renamed.

What you can do is compare what you just renamed to the next object in your arrays to be renamed. If the strings match then you need to update the hierarchy of that string with the objects new name.

ex.

Root|Obj1|Obj2|Obj3
Root|Obj1|Obj2
Root|Obj1

When you rename the third one.. (Root|Obj1) to (Root|Obj1_Bam)
You then need to update the other strings
Root|Obj1|Obj2 needs to become Root|Obj1_Bam|Obj2 in the string only this isn't your rename call. The final rename call needs to have whatever you are renaming it to.

rename "Root|Obj1_Bam|Obj2" "NewBam";

In my opinion there isn't really a best way to write this, you can write it a lot of ways. This is an approach I came up with in a few minutes. If you need some example code I can put more time into it and show you.

Let me know if this was explained horribly and you need more info.

-Kyle

Adam
10-26-2006, 03:58 AM
ah sorry I forgot to add a little bit more to my script. I forgot about this problem. I actually had to fix my rename script the other day becasue of this probelm. This is how I fixed what kwood is refering to. it is actually really easy to fix... So here is the updated script that I wrote above.


string $selList[] = `ls -l -sl`;
$k = 1;
for($sel in $selList)
{
string $selListUpdated[] = `ls -l -sl`;
rename $selListUpdated[$k -1] ("new" + $k);
$k++;
}

//BAM!

ctb
10-26-2006, 06:27 AM
Yeah~ This is what I want!

Thank you everyone.

I still have a lot to learn .. hee..hee...

yeah~

CGTalk Moderation
10-26-2006, 06:27 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.