Query Model Layers - Issue With Purged Layers


I leverage a python component that purges layers from the document.

With the new “Query Model Layers” component I noticed that, even when set to automatic update, it throws a caution error after a layer has been purged with the python component and returns a null value in the list of layer names output.


  1. A referenced Model Layer could not be found.

Note the null at index 54 in the layer list:

Python Code:

ghenv.Component.Name = "Purge Layers"
ghenv.Component.NickName = 'Purge Layers'
ghenv.Component.Message = 'Purge Layers'
ghenv.Component.Description = "Purges Layers By Name"

ghenv.Component.Params.Input[0].Description = "Activate"

ghenv.Component.Params.Input[1].Description = "Layer Names To Purge"

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino as rc

if A:
    # Set context to Rhino and disable drawing
    sc.doc = rc.RhinoDoc.ActiveDoc
    # Get all layer names sorted by depth (children first)
    layerNames = rs.LayerNames()
    layerNames.sort(key=lambda ln: ln.count("::"),reverse=True)
    # Purge Layers and their children
    for sln in layerNames:
        for pln in L:
            if pln in sln:
    # Enable drawing and set context to Grasshopper
    sc.doc = ghdoc

@dale I’m figuring there may be a better way to handle the layer purging in python to properly refresh/update the layer table for the Query Model Layers component? I just don’t know what it is but I’ll start looking.