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.
miauu's picture

.

I am not sure if the naming will works properly.

(
	global rol_Clone
	try(destroyDialog rol_Clone)catch()
	rollout rol_Clone ""
	(
		button btn_clone "Clone"
 
		on btn_clone pressed do
		(
			--	"get all cameras in the scene"
-- 			local objToCloneArr = for o in cameras where classOf o != TargetObject collect o
			--	"get cameras among selected objcets"
			local objToCloneArr = for o in selection where superClassOf o == camera and classOf o != TargetObject collect o
 
			local newObjsArr = #()
 
			fn uniqueNodeName node = if isValidNode node do
			(
				fn filtername nodeName suffix = (e = filterstring nodeName "_"; e[2] = suffix ; e)
				local oldName = filtername node.name "001", newName = oldName[1]+"_001"
				while (getNodeByName newname) != undefined do
				(
					newName = oldName[1] + "_" + (string = formattedPrint ((trimleft oldName[2] "0") as integer + 1) format:"03d")
					oldName = filtername newName string
				)
				newName
			)
 
			for o in objToCloneArr do
			(
				local newNodesArr = #()
				maxOps.CloneNodes o cloneType:#copy newNodes:&newNodesArr				
				newNodesArr[1].name = uniqueNodeName o
 
				append newObjsArr newNodesArr[1]
			)
			select newObjsArr
		)		
	)
	createdialog rol_Clone 
)
Igryl9l's picture

Thanks Miauu

Copying only cameras works as it should. Renaming does not work quite right.
Example: 001, 003, 002, 005, 004, 007 ...
Perhaps you need to record differently. In any case, thanks, it was useful information.

I will look for other ways to rename.

miauu's picture

.

(
	global rol_Clone
	try(destroyDialog rol_Clone)catch()
	rollout rol_Clone ""
	(
		edittext et_suffix "Suffix:" text:""
		edittext et_layerName "Layer Name:" text:""
		group "Offset:"
		(
			spinner spn_offsetX "X:" range:[-1e9,1e9,0] type:#worldunits
			spinner spn_offsetY "Y:" range:[-1e9,1e9,0]  type:#worldunits
			spinner spn_offsetZ "Z:" range:[-1e9,1e9,0]  type:#worldunits
		)
		button btn_clone "Clone"
 
		on btn_clone pressed do
		(
			local objToCloneArr = selection as array
			local newObjsArr = #()
			for o in objToCloneArr do
			(
				local newNodesArr = #()
				maxOps.CloneNodes o offset:[spn_offsetX.value,spn_offsetY.value,spn_offsetZ.value] expandHierarchy:false cloneType:#copy newNodes:&newNodesArr
				newNodesArr[1].name = o.name + et_suffix.text
				append newObjsArr newNodesArr[1]
			)
			if newObjsArr.count != 0 do
			(
				if et_layerName.text != "" then
				(
					if LayerManager.getLayerFromName et_layerName.text == undefined 	then
					(
						newLayer = LayerManager.newLayerFromName et_layerName.text
						for o in newObjsArr do newLayer.addNode o
					)
					else
					(
						newLayer = LayerManager.getLayerFromName et_layerName.text
						for o in newObjsArr do newLayer.addNode o
					)
				)
			)
		)		
	)
	createdialog rol_Clone 
)

Comment viewing options

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