[Closed] Rename object selection from list/array?
Have been flapping around in MaxScript for some hours trying to get this one to work… Any ideas?
What I’m trying to achieve:
Create a predefined list of saved names in a script (for example “square”, “circle”, “triangle”…)
Then, manually select objects in the scene in the order they need to be named
Push the magic button, and each object gets a new name appended to it from the predefined list
So, initially the scene has objects named for example “box01”, “box02”, “box03”. Afterwards they are named “box01_square”, “box02_circle”, and “box03_triangle”.
Does anyone know the correct incantation?
All help very much appreciated!
Kind regards,
Peter Spence.
You have 2 aray 1 – (for example “square”, “circle”, “triangle”…) 2 – objects named for example “box01”, “box02”, “box03” . then final names = uniqueName “box01” + “_” + “square”
Basic loop array.
Thank you for your input.
Here’s what I’ve been trying now. It doesn’t work, but you can see where I’m headed at least!
foo = #("square","circle","triangle")
(
for i in selection do i.name = uniqueName i.name + foo
)
This small update creates the correct result for the first item in the array.
But all the objects get the same suffix of course. So I need a bit of a loop added with incremental numbering.
foo = #("square","circle","triangle")
(
for i in selection do i.name = i.name + "_" + foo[1]
)
OK, got the next step working, but need to learn how to do loops…
This now suffixes the first object with the first array item, and then increases the countNum…
suffix = #("square","circle","triangle")
countNum = 1
(
for i in selection[countNum] do i.name = i.name + "_" + suffix[countNum]
countNum+=1
)
Well, I got there in the end!
Here’s the final solution:
myArray=selection
suffix = #("square","circle","triangle","blob")
countNum = 1
for i in myArray do
(
(
objectName = i.name + "_" + suffix[countNum]
countNum+=1
)
i.name = objectName
)
I select the objects in the order I want them renamed, and run the script. The rest is automagic.
Maybe someone else finds this useful!
What is the difference, in the end result, between your code and this:
(
myArray = selection as array
suffix = #("square","circle","triangle","blob")
for i = 1 to myArray.count do
(
myArray[i].name = myArray[i].name + "_" + suffix[i]
)
)