Make layers alphabetical automatically?

Is there a way to make the layers panel automatically insert new layers alphabetically? Rather than having to click on Name (which for some reason 1st gives me Z to A so I have to click on it twice)?

Thanks

2 Likes

I’ll reply, just because no one else did. The way users organize the layers palette is unique to all. I’m not sure of the issue you are questioning. The Panel is quite flexible and it would seem, that anyway you wish is possible. I have found it works just as you would expect any Folder organization to work. It places the New Layer where you tell it to be placed. If you want it somewhere else to fit your system just move it, with the arrows at top, or just place it in the position you want in the first place. Hope that helps…

1 Like

Thanks for the reply.
Yes, I understand, the way the Layers panel works is it allows you to move or position a layer to anyplace that you choose. And the layer will stay there even if you close and re-open the panel.

But I arrange my panel alphabetically so I wanted to know if there was a way to tell Rhino to automatically position any new layer alphabetically so I didn’t have to tell it to do so every time I create a new layer.

I’m constantly managing the Layers panel in Rhino, whereas in AutoCAD I don’t think about it because the default behavior is to automatically alphabetize the list.

1 Like

I think you are out of luck on this one.I did a search of all features and couldn’t find what you want. I manage my layers in a way that works & makes perfect since to “ME”. Others would not agree.
Your method may have to be suggested directly to Support—so—they can put it on the wish list. I would also think “you” could write a script to cover your wish.

Rhinoscript may be the easiest:
Here is a place to start:
http://wiki.mcneel.com/developer/rhinoscript
The Rhinoscript 101 Primer would be a good start…Good Luck…

Let us know if you find something in Rhinoscript…

This has come up a few times in the last couple of years and @Alain came up with a python script work around, which you can paste on a button.

http://discourse.mcneel.com/t/sort-layers-by-name

Alain, is it possible to turn off redraw while this code runs?

Hi Brian,

Did you try

scriptcontext.doc.Views.RedrawEnabled = False

Hi Alain, Yes I tried adding the snippet but couldn’t get it working, this is where I ended up;

import rhinoscriptsyntax as rs
import scriptcontext
from scriptcontext import doc
from System import Guid

sorted_layer_names = sorted([layer.FullPath for layer in doc.Layers 
  if layer.ParentLayerId == Guid.Empty], 
  key=lambda s: s.lower(), reverse=True)

tmp_layer_name = rs.AddLayer(Guid.NewGuid().ToString())
tmp = doc.Layers[doc.Layers.FindByFullPath(tmp_layer_name, False)]

scriptcontext.doc.Views.RedrawEnabled = False

for fp in sorted_layer_names:
    l = doc.Layers[doc.Layers.FindByFullPath(fp, False)]
    l.ParentLayerId = tmp.Id
    l.CommitChanges()
    l.ParentLayerId = Guid.Empty
    l.CommitChanges()

doc.Layers.Delete(tmp.LayerIndex, True)

scriptcontext.doc.Views.RedrawEnabled = True

You’re right. That’s won’t work. Sorry I don’t have an answer right now.

Thanks for the work-around anyway @Alain , the trick is to hide the layer panel while the code is executed, then it works instantly.

Great!