Problems with layer list order



Looking forward to testing here too.

Thanks Dale


Its working now. I get correct layer sort indexes with SR6.

Thanks Dale.


There is still a layer sorting order issue with Illustrator export. Most users won’t notice if they casually create layers from top to bottom, but in fact Illustrator export is according to layer creation order, and it totally ignores changes in Rhino Layers palette order.

Problem detailed here:

(Dale Fugier) #24

@NikWillmore, can you explain more why this is a problem?

@tim, is this something that is fixable?


Illustrator treats layer order as object overlap stacking order, visually. Yet I have no control over what Rhino layer order is exported into an .ai file since mere layer creation order is rather chaotic and arbitrary as I work, a mere historical artifact of my whims and attention span as I create a complex model on top of some architectural plan in a picture frame. But I need my lines and text on top of any eventually filled in areas or they won’t be visible. With perhaps hundreds of text annotations generated by Grasshopper, I can’t realistically manually reorder them in Illustrator to recreate my Rhino layer order.

I have developed a Python script to export objects as an SVG file to get around this issue for now.

(Dale Fugier) #26

I can assure you that layer creation is neither chaotic nor arbitrary. New layers are appended to the end of an internal array of layers, which resides on the active document. The display order - the order the layers appear in the Layer panel, has nothing to do with a layer’s layer index.

That said, when Rhino saves the document, it does save layers in their display order. This is done because the display order is not saved in the 3dm file. Thus when you reopen a file, the layers appear how you arranged them before saving. So one inconvenient work around it to save the document, reopen the document, and then export to .AI.

I’ve added a YouTrack item to modify the .AI exporter to write layers in display order. You can track the item here:

Layer Order DXF Export

Hi @dale,

I’ve noticed a specific moment when the UI and SortIndices appear to be out of sync: namely the moment a layer is added to the table:


The sort indices are correct after Sorted or Deleted events (or if the sort order is requested at the command line), but I need to detect the correct order programatically after an Added event (which, in the screenshot above, is the only event raised). Is there a way to force the change to register before I check the indices? I’m lifting your code from earlier in this thread.

internal static void OnLayerTableEvent(object sender, LayerTableEventArgs e)
    List<KeyValuePair<int, int>> sortList = new List<KeyValuePair<int, int>>(e.Document.Layers.Count);

    foreach (Rhino.DocObjects.Layer layer in e.Document.Layers)
         if (!layer.IsDeleted)
        sortList.Add(new KeyValuePair<int, int>(layer.LayerIndex, layer.SortIndex));

        delegate (KeyValuePair<int, int> firstPair,
        KeyValuePair<int, int> nextPair)
            return firstPair.Value.CompareTo(nextPair.Value);

    RhinoApp.WriteLine(e.EventType.ToString() + " " + e.Document.Layers.FindIndex(e.LayerIndex).Name);
    foreach (KeyValuePair<int, int> pair in sortList)
        RhinoApp.WriteLine("Name = {0}, LayerIndex = {1}, SortIndex = {2}", e.Document.Layers[pair.Key].Name, pair.Key, pair.Value);

This is Rhino 6 by the way.



(Dale Fugier) #28

Hi @Jon,

Yes, this is true. The sort order cannot be updated until the new layer has been and added (and thus can be included in the sort).

– Dale


Hi @dale,

I don’t follow. The new layer (Layer 04) has already been added to the LayerTable – as evident in the app writelines visible in the screenshot. The problem is that it’s been added in the wrong sort position.

Is there a fix for this? Clearly the sort order gets corrected at some (later) point, but as far as I can tell, there’s no catchable event to indicate when the correction has occurred.