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.
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.
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)