Rename objects in a linear order based on their position?

Rename objects in a linear order based on their position?

neilcooper33
Enthusiast Enthusiast
1,055 Views
2 Replies
Message 1 of 3

Rename objects in a linear order based on their position?

neilcooper33
Enthusiast
Enthusiast

Hi

 

I have a grid of terrain squares which i'm trying to rename in order from the bottom left, up to the top right in rows... i've attached an image highlighting what i'm trying to do.  

 

Does anyone have any idea how to go about this please?

 

I realise that if i select the objects in this order, I can use the Max rename tool to do what i want... but i have to do this a number of times so hoping for a way i can automate this.

 

Thanks in advance! 🙂

 

Neil

0 Likes
Accepted solutions (1)
1,056 Views
2 Replies
Replies (2)
Message 2 of 3

Swordslayer
Advisor
Advisor
Accepted solution

You can sort the selection like this:

 

fn compPos obj1 obj2 =
(
	if obj1.pos.y < obj2.pos.y then -1
	else if obj1.pos.y > obj2.pos.y then 1
	else
	(
		if obj1.pos.x < obj2.pos.x then -1
		else if obj1.pos.x > obj2.pos.x then 1
		else 1
	)
)

objs = selection as array
qsort objs compPos
select objs

And from there either use the rename tool as you said, use uniqueName if you want to start from the highest existing number automatically:

 

 

for obj in selection do obj.name = uniqueName "prefix"

or do the counting yourself if you want to start from one (or further personalize it):

 

 

for i = 1 to selection.count do selection[i].name = "prefix" + formattedPrint i format:".3i"
Message 3 of 3

neilcooper33
Enthusiast
Enthusiast

that's great! thanks for your help again 🙂

 

Neil

0 Likes