Clone objects and add a name extention

Hey guys.. looking for a script that will clone All selected objects, and add a name extension to the original object's names.
For example Box_01 and Box_02 cloned to Box_01_New-text-here and Box_02_New-text-here, than create a new layer and be able to name that for the group of selected objects that were cloned.

Comments

Comment viewing options

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

Hello Miauu

Tell me how to fix the code?
In the process of renaming objects, the name is skipped - 001, 003, 005 ... I can not find a solution.

Help me please.

AttachmentSize
copyrename.ms 535 bytes
miauu's picture

.

How I can reproduce the problem? How many objects I have to select, what suffix I have to use?

Igryl9l's picture

I tried to add a name

I tried to add a name selection when copying.

newNodesArr.name = Uniquename bg_8.text

The problem occurs when you copy the same name again - the script skips the number.
Example: copy of “Name 001” = “Name 003”, “Name 005” ...
Besides this problem, the script does everything right.

As a result of copying, it is necessary to obtain the selected name and serial number of the object - "Name 001", "Name 002", "Name 003" ...
If you do not enter a name, then get - "001", "002", "003" ...
Ideally, if the object to be copied is named “Name 001_01” or “Name 001_001”, when copying, you need to get “Name 002”, “Name 003” ...

Please tell me how to write it right?
Thanks your help!

miauu's picture

.

Try this:

	fn uniqueNodeName node = if isValidNode node do
			(
				s = filterstring node.name "_"
				newName = s[1] + "_"
				if s.count == 1 then
				(
					newName += "001"
				)
				else
				(
					--	"this"
					newName += formattedPrint ((trimleft s[2] "0") as integer + 1) format:"03d"
					--	"or this"
-- 					newName = uniqueName node.name
				)
				newName
			)
Igryl9l's picture

Duplicates

The script creates duplicates when you copy the original object again.
Example:
When copying "001" we get "001_001", "001_002", "001_003" ...
When we copy the original object "001" again, we get the same "001_001", "001_002", "001_003" ... however, must continue to "001_004", "001_005" ...

miauu's picture

.

Try this:

--	"this"
					-- newName += formattedPrint ((trimleft s[2] "0") as integer + 1) format:"03d"
					--	"or this"
					newName = uniqueName node.name
Igryl9l's picture

Alas.

I have added a line. Now numbering skips the unit - 002, 004, 006 ...

tuxmask75's picture

Perfect as always Miauu!!

Perfect as always Miauu!! thanks!

miauu's picture

.

Glad to help. :)

Igryl9l's picture

Hello Miauu

I took part of your code to copy the camera along with its target and added another code to it. It works well, without errors.
Please tell me how to make the code work only for cameras.
И как добавить к имени «_001» вместо «_01».
Example:
copy of "Camera 001" = "Camera 001_001"
copy of "Camera 001_001" = "Camera 001_002"
That's what happened - Copy camera.
Thanks for your help.

AttachmentSize
copy_camera.ms 980 bytes

Comment viewing options

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