Duplicate Layer + or objects


I see this is not available on OSX Rhino by either right+click layers panel or from layer icon.

Can this be accomplished with python? I don’t see anything in python reference layers commands.

Thanks, Randy


Duplicating a layer with or without its objects is certainly possible via Python. The main problem is that neither GetLayer() nor anything like ListBox() are implemented on Mac yet, so having a dialog to choose which layer to duplicate is not currently possible. It is possible to present the user a list of strings that represent the layer names, but if you have a lot of them, it will prove unwieldy.



Hi Mitch,
Well, I was trying on MacRhino, but really I am setting up files to render with Flamingo, Windows only. I have various versions of a piece to render with different colours. So my thinking was to duplicate layers and objects then apply the materials to each sub-layer. So I have a main layer called “Version 1” and all it’s sub-layers usually 5-10, then duplicate Version 1 as Version 2, etc. Then apply materials to each layer. That way I just turn off version 1 and turn on version 2 then render.
I don’t see getLayer anywhere;



Hi Randy,
Check the “userinterface” section instead of “layer”. You will find rs.GetLayer() there.


Thanks @djordje, Loads of stuff there.


Does GetLayer() now work on Mac? Last time I tested it didn’t…

Ahh, it does…

OK, here is a simple dupe layer script to test… It doesn’t currently duplicate anything other than layer color… If you need it to dupe other things, that can probably be added.


DupLayerAndObjs.py (724 Bytes)


Hi Mitch thanks, will check it shortly and get back to you, Over in Flamingo land for a few more minutes.


Well, cool @Helvetosaur

Maybe time later to look at your script a bit more. wondering about copying subLayers as well.

Like the list box and also the option to select objects layer with Pick.



So, you want to duplicate the layer and all its sublayers? I have a vb rhinoscript that does that, I can try to convert that into Python, but I won’t have time today, maybe tomorrow…



Hi Mitch, that is the plan.

I may play with the script you did today. If you have time and want to try to convert the VB script, that would be great. Always appreciate your help!

Thanks, Randy

(Marlin Prowell) #11

Looks like some Layer panel context menu items that are in Windows V5 are missing on the Mac. Logged as a bug.


Took awhile - below is a script that duplicates a layer and all its sublayers plus all the objects on them. The layer chosen can be a sublayer itself. The layer selected to be copied gets a " - Copy" suffix and is placed at the same sublevel as the layer being copied; the sublayers don’t get name changes. This mimics more or less what the function in Windows Rhino does.

For the moment, only layer color is copied over to the duplicated layers, I may work on it some more perhaps and make it copy over other layer attributes such as material, etc.


DupLayersSublayersAndObjs.py (1.7 KB)


Great, will look at that shortly, just starting my day here - espresso #2. I just started a python online course at Codecadamey , I hope this helps me learn some python.

Cheers … Randy


OK, cool… I recommend having a look at the stuff here as well - particularly the 101 manual which will show you how python relates to Rhino with examples and exercises…



I also need to add that the above script is a bit tricky…

The first pitfall is the fact that you can have same-named sublayers in V5, and the second is because you do not know how deep layer nesting will be.

There are a few ways to deal with the first part, but the only way to deal with the unknown nesting level is via recursion - where a function calls itself, inside itself. This is a bit difficult to wrap your head around… The classic joke is:

“In order to understand recursion, it is first necessary to understand recursion…”



Sounds like Escher to me.

All my Python / Rhino tabs; more time, I need more time LOL

I think the first thing is understanding a definition as opposed to just lines of code, which is all I have done up to this point. I have gone through Plethora, Jose’s tutorials about 6 months ago, it seems i have to put them into practise with something I need, which is not always obvious until I try to do something like Duplicate layers & objects!

Happy Monday … Randy


Think of a definition as just a custom method like the other rhinoscriptsyntax methods:

It has inputs (arguments) - as many as you want, all optional; and an output (return) - also optional

Definitions allow you to encapsulate bits of simple code and re-use and combine them.

Also, if you encapsulate your main routine in a definition, you can escape gracefully from it in case of error or user abort using “return” - which you cannot do if you are outside a definition, return doesn’t work. That’s why you often see even the simplest of operations encapsulated in a definition.



OK, below is the revised version which copies all main layer attributes as well…

DupLayerSublayersAndObjs.py (2.4 KB)