Duplicate Layer + or objects


#1

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


#2

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.

–Mitch


#3

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;

Thanks


#4

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


#5

Thanks @djordje, Loads of stuff there.


#6

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.

–Mitch

DupLayerAndObjs.py (724 Bytes)


#7

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


#8

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.

Cheers


#9

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…

–Mitch


#10

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.


#12

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.

–Mitch

DupLayersSublayersAndObjs.py (1.7 KB)


#13

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


#14

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…

–Mitch


#15

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…”

–Mitch


#16

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


#17

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.

–Mitch


#18

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

DupLayerSublayersAndObjs.py (2.4 KB)

–Mitch