Notifications
Clear all

[Closed] Duplicate Render Elements

I am working on a simplyfied and improved Render Elements script, and I want to add a “duplicate” button that duplicates all the render elements. I cannot figure out how to do this.

My thinking is that I should take all the render elements in an array, copy that array, then add “_copy” to all the render elements in the copied array, and then use the addRenderElement() funciton to add the new renamed elements.

But the problem is that they are not added, just renamed. Or the original array is renamed.

How do I break the connection between the old array of render elemetns and the new one?

Here is my code so far for the duplicate function:

re = maxOps.GetCurRenderElementMgr()

theManager = maxOps.GetRenderElementMgr #Production

RenderElementsIndex = for n = 1 to (theManager.numrenderelements ()) collect n

RenderElements = for n = 0 to (theManager.numrenderelements () – 1) collect (re.getrenderelement n)

newRenderElements = copy RenderElements #nomap
oldRenderElementNames = for i in RenderElements collect i.name

re.RemoveAllRenderElements()
for i in RenderElementsIndex do
(
newRenderElements[i].name = (oldRenderElementNames[i] + “_copy”)
)

for i in newRenderElements do
(
re.addrenderelement(i)
)

1 Reply

hi Kristian,
here is the modified code

(

re = maxOps.GetCurRenderElementMgr()

theManager = maxOps.GetRenderElementMgr #Production
print theManager
RenderElementsIndex = for n = 1 to (theManager.numrenderelements ()) collect n

RenderElements = for n = 0 to (theManager.numrenderelements () - 1) collect (re.getrenderelement n)

newRenderElements = copy RenderElements #nomap

oldRenderElementNames = for i in RenderElements collect i.elementname

modifiedArray = for elem in newRenderElements collect (classOf elem )

for i=1 to modifiedArray.count do
(
re.addrenderelement (modifiedArray[i] elementname:(oldRenderElementNames[i]+"_copy"))
)

)