Purge Layer not working

Hi,

I am trying to use the PurgeLayer function in Rhionscript and it is failing to delete the layer in the screen shot. The layer has children, all of which have geometry in them. I want to delete the geometry, children and the parent layer from the file. Any help would be greatly appreciated.

Eric

image

@eric.bunn - what version of Rhino? Can you provide a sample file?

– Dale

Dale,

I’m using Rhino 6. I have attached the Rhino File.

EricDelete Layer Example.3dm (172.4 KB)

Hi @eric.bunn,

If I recall correctly, the LayerTable.Purge method in Rhino 6, which is used by rs.PurgeLayer, was only capable of purging a single layer and would not traverse a layer tree.

In Rhino 7, the LayerTable.Purge method will traverse a layer tree and purge.

For example, this works (almost) in Rhino 7 on your file:

import rhinoscriptsyntax as rs
rs.PurgeLayer("Mold Box Template")

What I mean by almost is that the Mold Box Template::Drill Points layer contain some instance definition geometry. You’ll need to delete those instance definitions before you can delete that layer.

Hope this helps.

– Dale

Could I delete my block instances and then delete the child layers one at a time followed by the parent layer?

Or alternatively activate each layer, delete the geometry and then the layer?

Eric

That would be my approach.

– Dale

Thanks

I don’t know if this is the best way to do it but this worked:

if rs.IsLayer(layer):
        #Delete Blocks in Mold Box
        rs.DeleteBlock("Hinge_Holes_Lid")
        rs.DeleteBlock("Hinge_Holes_RR")
        rs.DeleteBlock("Toggle_Holes")
        #Get Layer Children
        children = rs.LayerChildren(layer)
        for i in children:
            count = rs.LayerChildCount(i)
            print(i,count)
            if count == 0:
                rs.PurgeLayer(i)
            else:
                inner = rs.LayerChildren(i)
                for j in inner:
                    print(j)
                    rs.PurgeLayer(j)
                    rs.PurgeLayer(i)
        rs.PurgeLayer(layer)

Thanks for the help.

Eric