I’m wondering if the codes below can be put together and have a success(T/F) output?
Ends up with a clean file in one go if possible.
Coming from these three threats:
using System.Linq;
private void RunScript(bool update, ref object A)
{
A = Rhino.RhinoDoc.ActiveDoc.InstanceDefinitions.Select(b => b.Name).ToList();
if(update)
Component.ExpireSolution(true);
Component.Message = "GetBlockNames";
}
private void RunScript(bool Purge, string Blocks)
{
if(Purge)
{
var idef = RhinoDocument.InstanceDefinitions.Find(Blocks);
if (null != idef)
RhinoDocument.InstanceDefinitions.Delete(idef);
}
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino as rc
if Purge:
# Set context to Rhino and disable drawing
sc.doc = rc.RhinoDoc.ActiveDoc
rs.EnableRedraw(False)
# 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 Layers:
if pln in sln:
rs.PurgeLayer(sln)
break
# Enable drawing and set context to Grasshopper
rs.EnableRedraw(True)
sc.doc = ghdoc