ScriptSpot

Forum topic · General Scripting

Clone Layer

By netkingZ · 2016-06-22

Description

Hello guys,
i found this script:


fn cloneLayers prefix: sufix: 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
				(
				

				str = filterstring lay.name "_"
				if prefix != unsupplied do str[1] = prefix
				if sufix != unsupplied do str[str.count] = sufix
				newname = str[1] ; for i = 2 to str.count do newname+="_"+str[i]
				maxops.clonenodes nodes expandHierarchy:on cloneType:#copy actualNodeList:&an newNodes:&nn
				newlayer = layermanager.newLayerFromName newname
				for n in nn do newlayer.addNode n
				)
				)
				)
				
				cloneLayers prefix:"new" sufix:"Dubbys" hidden:off

I want to clone only selected layer. how can do this?
Now the scripts clone layer but objects it doubles inside new layer How can fix this?

Thanks

Comments (3)

Nice one but...

brainsgonedead · 2016-10-17

Hi, this is a great script but I keep my daylight system on the default layer and every layer I go to clone it clones the lighting system into my cloned layer.

Does anyone have any idea why or what to change in the script above by barigazy please?

barigazy · 2016-06-23

This is the my code :) which btw clone nodes in hidden or visible layers
On the other hand you can use below code to clone only nodes inside current (selected) layer

fn cloneLayers prefix:"" sufix:"" =
(
layer = for l = 0 to layerManager.count-1 where (lay = layerManager.getLayer l).current do exit with lay
if (nodes = refs.dependentNodes layer.layerAsRefTarg).count != 0 do
(
str = filterstring layer.name "_"
if prefix != unsupplied do str[1] = prefix
if sufix != unsupplied do str[str.count] = sufix
newname = str[1] ; for i = 2 to str.count do newname+="_"+str[i]
maxops.clonenodes nodes expandHierarchy:on cloneType:#copy actualNodeList:&an newNodes:&nn
newlayer = layermanager.newLayerFromName newname
for n in nn do newlayer.addNode n
)
)

cloneLayers prefix:"new" sufix:"Dubbys"

netkingZ · 2016-07-07

Thanks you