How to rename detached objects in a layer based on their ascending numbering order.

Please note, I am happy to pay someone to write this short script for me, so please let me know your fee to do this for me :)

Here's my request.

I have objects in a layer (I have many layers, 100) and some of those objects (let's call these the 'original' objects), are named - 006_145_15, 006_145_18, 006_145_25 etc.

Note that they are suffixed with _15, _18 or _25. Their prefixes (in my example, 006_145 is the same within its layer but will be a different sequence of numbers in other layers, but still in that similar 3 digit grouping pattern).

However, also within that same layer, there are objects that are the faces of these 'original's that have been detached - so for example, in that same layer, there are objects names as Object47, Object519, Object521.

Please note that in some layers, there may not be three but only two 'original' objects, so in those cases, those two might be suffixed _15 and _18, or _18 and _25 or _15 and _25.

Now... the script....

I need a script that'll got through each layer and rename the Objects that it finds starting with the name "Object" and rename them with its corresponding Parent Object Name, but with the suffix "_Ends".

So, in the above example;

Object47 would be renamed 006_145_15_Ends,
Object519 would be renamed 006_145_18_Ends,
Object521 would be renamed 006_145_25_Ends.

As you can see, the ascending numbering of the Object names correspond with the numbering of the original parent name.

I'm sure this is just a few lines of code for an expert who knows how to do this :)

As I say, I'm happy to pay for this (let me know how much you'd like).

Many thanks.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
JezUK's picture

Hi Jahman, It’s just a

Hi Jahman,

It’s just a renaming exercise, I’m not looking to delete objects and detach again in this scene.

Maybe it’s a coincidence because everything was created in order.

jahman's picture

.

try the second one I posted

jahman's picture

.


... and rename them with its corresponding Parent Object Name

how do you determine which object is the parent?
perhaps it would be better to name these side elements objects at the same time when you detach them

JezUK's picture

As mentioned, there are only

Hi Jahman,

Thanks for asking, I really appreciate it :)

As mentioned, there are only a maximum of 3 parents in a layer with either a _15, _18 or _25 suffix (the prefix is a fixed name). In some cases there are only 2 objects with either one of those suffixes (could be _15 & _18, or _18 & _25, or _15 & _25, or as I said, all three suffixes).

So the corresponding 2 or 3 *detached* Objects (prefixed with the word "Object") will be in ascending order as well...

So whatever the numbers after the word "Object" are, eg Object234, Object345, Object456, those are in ascending order too, so those will be correspond to lowest to highest, of either _15, _18 and _25 *respectively*.

As I say, there might be 2 (not 3) parents, so, again, it's just in ascending order. If there are only 2 parents and say and they are _18 and _25, then the two detached objects which will also have ascending suffix numbers within that layer just get renamed respectively (ie lowest Objectxxx gets the _18 and the highest Objectxxx gets the _25 suffix).

You can't name these side elements at the same time manually, that's why I need the script. There'll be 1000's of objects to do like this as I have over a 100 layers and each layer has 2 or 3 objects and this is for just one product size (there are many sizes). So, this'll be in the thousands and is all to be used in a WebGL environment.

So it simply has to be automated :)

It's just a renaming exercise based on what's in a layer (2 or 3 parent objects) and renaming the "Object" suffixed geometry in the same ascending order in the syntax of my original opening post.

If you can help me, that'd be really, really great and very, very much appreciated :)

Thank you!

jahman's picture

.

It is just a coincidence that you have these Object### in ascending order.
If you delete Object123 then the next time you detach anything with prefix 'Object' it will take this unused name.

Open a blank scene and run
example:

delete objects
gc()
 
b = box()
convertToPoly b
 
-- 1. first we detach 5 sides of the box
for i = 1 to 5 do
(
	part_name = uniqueName "box_part"
	polyop.detachFaces b #{i} delete:false asNode:true name:part_name
)
 
-- 2. now we delete any detached side
delete (getNodeByName "box_part005")
 
-- 3. lets detach the last one and see what Name it will have
part_name = uniqueName "box_part"
(polyop.detachFaces b #{6} delete:false asNode:true name:part_name)
 
messageBox ("Expected: box_part006  got: " +  part_name)

but, if you sure that it is safe try this

for i = 0 to LayerManager.count - 1 do
(
	local nodes 
	(layer = LayerManager.getLayer i).nodes &nodes
 
	local object_nodes = #()
	local originals    = #()
 
	for n in nodes do
	(
		if MatchPattern n.name pattern:"Object*"  then append object_nodes n else append originals n
	)
 
	if originals.count != object_nodes.count then
	(
		messageBox (layer.Name + " nodes count mismatch")
	)
	else
	(
		fn sortbyname a b = stricmp (toUpper a.name) (toUpper b.name)
 
		qsort object_nodes sortbyname
		qsort originals    sortbyname
 
		for j = 1 to object_nodes.count do object_nodes[j].Name = originals[j].name + "_Ends"		
	)	
)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.