Home Technical Talk

*SOLVED* 3ds Max - Duplicate Layer with the same content inside

polycounter lvl 8
Offline / Send Message
Pinned
MaxHoek polycounter lvl 8
Hey, i cant find the feature in 3ds max 16 but maybe could be reached with a bit of scripting. 

My problem right now is:  I`m working on a very big project of my own with multiple layers and sublayers with objects inside to have the best organization i could have. Now my HP is ready and i want to have the same layers stucture also for my LP without creating hundreds of layers handish and copying every single object in it. 

I`d like to duplicate a layer, the layer should have the same content of the first. With all sublayers and objects inside as copy, no instance. Maybe the new folder with a sufix like "_LP" at the end. 

Is there any smart way for this problem? Or is there maybe a script? 


Every layer is like this and copy paste in new layers would be soooo time consuming and painfull :dizzy:

Replies

  • monster
    Options
    Offline / Send Message
    monster polycounter
    If I understand you correctly, this is pretty easy with script. The code below works on a viewport selection not on a Layer Explorer selection. It just clones all the object then puts them in new layers.

    A built in way would be to merge the max file into itself and turn off "Match Layers", but that option isn't doing anything for me. *shrugs*

    (
    	--//SUFFIX TO ADD TO NEW LAYERS
    	suffix = "_LP"
    	
    	--//FUNCTION TO GET OR CREATE A LAYER FROM A NAME
    	fn getOrCreateLayerFromName layerName =
    	(
    		newLayer = layermanager.getLayerFromName layerName
    		
    		if newLayer == undefined do
    		(
    			newLayer = layermanager.newLayerFromName layerName
    		)
    		
    		newLayer
    	)
    	
    	--//GET THE CURRENT SELECTION
    	selObjs = getCurrentSelection()
    	
    	--//CLONE THE NODES
    	maxOps.cloneNodes selObjs cloneType:#copy actualNodeList:selObjs newNodes:&newObjs
    	
    	--//ITERATE THE SELECTION TO ORGANIZE THE NEW NODES INTO NEW LAYERS
    	for o = 1 to selObjs.count do
    	(
    		--//CREATE THE LAYER IF NEEDED
    		oldLayer = selObjs[o].layer
    		
    		newLayer = getOrCreateLayerFromName (oldLayer.name + suffix)
    		
    		--//ADD THE CLONED OBJECT TO THE NEW LAYER
    		newLayer.addNode newObjs[o]
    		
    		--//CHECK THE PARENT OF THE OLD LAYER
    		pLayer = oldLayer.getParent()
    		
    		if pLayer != undefined do
    		(
    			newParent = getOrCreateLayerFromName (pLayer.name + suffix)
    			newLayer.setParent newParent
    		)
    	)
    	
    	select newObjs
    )
  • MaxHoek
    Options
    Offline / Send Message
    MaxHoek polycounter lvl 8
    WOW! thats exactly what i want! awesome, you save my life! xD 
    thank you very much for this quick and nice answer! I really appreciate it! 
  • wakkamis
    Options
    Offline / Send Message
    wakkamis polycounter lvl 15
    Thanks! This script is still helping out a couple year later! 
  • RobH2
    Options
    Offline / Send Message
    RobH2 polycounter lvl 4
    Ok, so now it's years later and this helped me tremendously. Nice. Thank you!!!
  • Kidd Kosmonaut
    Options
    Offline / Send Message
    Kidd Kosmonaut polycounter lvl 5
    Hopping on this 'your script saved the day train' to say YOUR SCRIPT SAVED MY DAY, thanks!!
  • monster
    Options
    Offline / Send Message
    monster polycounter
    I have no memory of even writing this! :smiley:
  • Infernowar
    Options
    Offline / Send Message
    monster said:
    I have no memory of even writing this! :smiley:

    Man thanks so much you saved me a lot of time!!!!! THANKS!
  • Mepra
    Options
    Offline / Send Message
    Mepra polycounter lvl 4
    This script saved me today , thanks man !
  • aypheros
    Options
    Offline / Send Message
    aypheros polycounter lvl 5
  • strickahduda
    Options
    Offline / Send Message
    strickahduda polycounter lvl 3
    @monster dude you are amazing! Thank you sooo much! Still helped now that it's 2020. I dunno why such a simple feature has not yet added. (Im using 3ds Max 2019 tho)
  • Uzor1011
    Options
    Offline / Send Message
    @monster Man! you've saved yet another person, thank you sooo much. Simply amazing! It's just soo relevant and useful. In my case, I needed them as instances, so I tweaked the script just a tiny bit ( I had no prior knowledge on writing max scripts, yet it worked). I just changed the copy to instance (line 20) and it worked just fine. Thanks again @monster .


    (
    --//SUFFIX TO ADD TO NEW LAYERS
    suffix = "_LP"
    --//FUNCTION TO GET OR CREATE A LAYER FROM A NAME
    fn getOrCreateLayerFromName layerName =
    (
    newLayer = layermanager.getLayerFromName layerName
    if newLayer == undefined do
    (
    newLayer = layermanager.newLayerFromName layerName
    )
    newLayer
    )
    --//GET THE CURRENT SELECTION
    selObjs = getCurrentSelection()
    --//CLONE THE NODES
    maxOps.cloneNodes selObjs cloneType:#instance actualNodeList:selObjs newNodes:&newObjs
    --//ITERATE THE SELECTION TO ORGANIZE THE NEW NODES INTO NEW LAYERS
    for o = 1 to selObjs.count do
    (
    --//CREATE THE LAYER IF NEEDED
    oldLayer = selObjs[o].layer
    newLayer = getOrCreateLayerFromName (oldLayer.name + suffix)
    --//ADD THE CLONED OBJECT TO THE NEW LAYER
    newLayer.addNode newObjs[o]
    --//CHECK THE PARENT OF THE OLD LAYER
    pLayer = oldLayer.getParent()
    if pLayer != undefined do
    (
    newParent = getOrCreateLayerFromName (pLayer.name + suffix)
    newLayer.setParent newParent
    )
    )
    select newObjs
    )

     
  • Sefcheg
    Options
    Offline / Send Message
    Sefcheg polycounter lvl 8
    I added some modification - now it removes new indexes from new objects and saves names in original objects, but this script still doesn`t save hierarchy. All new layers are in default 0 layer.

    Strange. Sometimes it works, sometimes not. I restarted max and all layer structure in copied layers saved
  • lego9430
    Options
    Offline / Send Message

    Hi guys, i feel so ignorant, but: how do you run the script? Well, in "Customize User Interface" what Category must be chosen??? As when I run it, on Run Script, nothing happens!


    I am a dummy, sure, but does not make any sense to you?

Sign In or Register to comment.