[Closed] Duplicate Layer with the same content inside
Hi!
I can’t find this feature in 3ds max, maybe could be reached with a bit of scripting… I’d like to make a copy of a lyaer, the new layer should have the same content of the first, copy… not instance.
Is it possible?
Thanks a lot!
Like this
fn cloneLayer layername clonename: =
(
if (l = LayerManager.getLayerFromName layername) != null do
(
if (nodes = refs.dependentNodes l.layerAsRefTarg).count != 0 do
(
maxops.clonenodes nodes expandHierarchy:on cloneType:#copy actualNodeList:&an newNodes:&nn
if clonename == unsupplied do clonename = layername + "_copy"
newlayer = layermanager.newLayerFromName clonename
for n in nn do newlayer.addNode n ; select nn
)
)
)
--example
sphLay = layermanager.newLayerFromName "SphereLayer"
for s = 1 to 5 do (sphLay.addNode (sphere()))
--using this u will get new layer with cloned spheres named "SphereLayer_copy"
cloneLayer "SphereLayer"
--if you want cloned layer with unique name use this
cloneLayer "SphereLayer" clonename:"CloneSphere"
thank you man!
It works. What should I do is to copy/paste manually the name of the layer I want to clone.
I know that in max can’t be recognize the layer is selected, but do you think that is it possible to clone the layer that is unhidden?
Take a look to this code:
fn modifyObjsByLayer hidden: =
(
local nodes = #()
for l = 0 to layerManager.count-1 where (lay = layerManager.getLayer l).ishidden == hidden do
(
join nodes (refs.dependentNodes lay.layerAsRefTarg)
)
if nodes.count != 0 do
(
for o in nodes do
(
--this should be added the action to execute
)
) ; nodes
)
modifyObjsByLayer hidden:off
I’m not a good scripter, that code has been written by another user, but do you thing it could be implemented in yours in the way that I can clone the unhidden layer? And the name of the new layer should be the same as the first plus a suffix and a prefix.
Thank you anyway man!
Yup. Code that you posted is written by who? Are you not recognize the style?
Here we go
fn cloneLayers hidden:off prefix: sufix: =
(
for l = 0 to layerManager.count-1 where (lay = layerManager.getLayer l).ishidden == hidden do
(
if (nodes = refs.dependentNodes lay.layerAsRefTarg).count != 0 do
(
if prefix == unsupplied do prefix = "_"
if sufix == unsupplied do sufix = "_copy"
maxops.clonenodes nodes expandHierarchy:on cloneType:#copy actualNodeList:&an newNodes:&nn
newlayer = layermanager.newLayerFromName (prefix+lay.name+sufix)
for n in nn do newlayer.addNode n
)
)
)
Above code works on all hidden or unhidden layers in LayerManager but for now let say we have (not hidden) layer named “Originals” which we need to clone.
And this are the results by using cloneLayers fn :
-- if you use this concept
cloneLayers ()
-- your cloned layer will be named "_Originals_copy"
cloneLayers prefix:"new_"
-- result > "new_Originals_copy"
cloneLayers prefix:"#" sufix:"_clone"
--"#Originals_clone"
Yes it was your damn working code I was ironic.
When I execute your code (the first) nothing happens… have I to change something?
I just read “cloneLayers()” as result but but the layermanager remains the same.
Ok my mistake :)… forgot to add “cloneLayers ()” at the end of the script
don’t look at me so… this is not my language
You are only create fn by using my code.
Add this line at the end and run it again
cloneLayers prefix:"#" sufix:"_clone"
Ehy man, this is your script I’ve modifier a bit
fn cloneLayers hidden:off =
(
for l = 0 to layerManager.count-1 where (lay = layerManager.getLayer l).ishidden == hidden do
(
if (nodes = refs.dependentNodes lay.layerAsRefTarg).count != 0 do
(
layerName = lay.name
namePos = substring layerName (layerName.count-1) 2
newName = layerName - namePos
maxops.clonenodes nodes expandHierarchy:on cloneType:#copy actualNodeList:&an newNodes:&nn
newlayer = layermanager.newLayerFromName (newName + "nurbs")
for n in nn do newlayer.addNode n
)
)
)
cloneLayers ()
What I want: I show with an example.
-First layer name: “esp_code_hp”
-Final clone layer name: “esp_code_nurbs”
I just want the new clone layer has the same name has the before but with the “hp” suffix replaced with “nurbs”.
In theory the code should work, but I suppose the wrong line is “newName = layerName – namePos”, in my naive mind I subtract to the layername the suffix “hp” :)…
Consider the length of layername is variable (ex: “esp_xxxx_hp”, “esp_xx_hp” …)
Bye!