C3D-0382 · C-Store: V-NODE/V-CTRL symbol guts -> layer 0, delete empty ones [C3D-CSVNODE] done
Moves in-block symbol guts on V-NODE* and V-CTRL* layers to layer 0 (inheriting each insert's real layer, like the control-point example), then deletes any of those layers now fully empty; keeps any with standalone top-level geometry. Guts only - never touches top-level entities.
C# payload
// C-Store: move V-NODE* and V-CTRL* in-block symbol guts to layer 0 (so they inherit the real
// insert layer, like HORIZONTAL_AND_VERTICAL_CONTROL_POINT), then delete any V-NODE*/V-CTRL*
// layer that is now completely empty. A layer with standalone (top-level) geometry is KEPT -
// the user may have that for a reason. Only guts get relocated.
Log("drawing: " + Db.Filename);
var bt = (BlockTable)Tx.GetObject(Db.BlockTableId, OpenMode.ForRead);
var lt = (LayerTable)Tx.GetObject(Db.LayerTableId, OpenMode.ForWrite);
var targets = new List<string>();
foreach (ObjectId id in lt) {
var l=(LayerTableRecord)Tx.GetObject(id,OpenMode.ForRead);
if (l.Name.StartsWith("V-NODE",StringComparison.OrdinalIgnoreCase) || l.Name.StartsWith("V-CTRL",StringComparison.OrdinalIgnoreCase)) targets.Add(l.Name);
}
var tset = new HashSet<string>(targets, StringComparer.OrdinalIgnoreCase);
Log("V-NODE*/V-CTRL* layers: " + targets.Count);
foreach (var n in targets){ var l=(LayerTableRecord)Tx.GetObject(lt[n],OpenMode.ForWrite); l.IsFrozen=false; l.IsOff=false; l.IsLocked=false; }
// move ONLY in-block guts to 0 (leave any top-level standalone geometry where it is)
int moved=0;
foreach (ObjectId bid in bt) {
var def=(BlockTableRecord)Tx.GetObject(bid,OpenMode.ForRead);
if (def.IsLayout) continue; // guts only
var ids=new List<ObjectId>(); foreach (ObjectId sid in def) ids.Add(sid);
foreach (var sid in ids){
var probe=Tx.GetObject(sid,OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Entity;
if (probe==null || !tset.Contains(probe.Layer)) continue;
var e=(Autodesk.AutoCAD.DatabaseServices.Entity)Tx.GetObject(sid,OpenMode.ForWrite);
e.Layer="0"; moved++;
}
}
Log("moved " + moved + " in-block guts to 0");
{ var cl=(LayerTableRecord)Tx.GetObject(Db.Clayer,OpenMode.ForRead); if (tset.Contains(cl.Name)){ Db.Clayer=lt["0"]; Log("current layer was target - switched to 0"); } }
// delete only fully-empty target layers
int deleted=0, kept=0;
foreach (var n in targets){
int still=0;
foreach (ObjectId bid in bt){ var def=(BlockTableRecord)Tx.GetObject(bid,OpenMode.ForRead); foreach (ObjectId sid in def){ var e=Tx.GetObject(sid,OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Entity; if (e!=null && !e.IsErased && e.Layer.Equals(n,StringComparison.OrdinalIgnoreCase)) still++; } }
if (still>0){ kept++; Log(" kept " + n + " (" + still + " entities)"); continue; }
try { var l=(LayerTableRecord)Tx.GetObject(lt[n],OpenMode.ForWrite); l.Erase(); deleted++; }
catch (System.Exception ex){ Log(" could not delete " + n + ": " + ex.Message); }
}
Log(string.Format("deleted {0}, kept {1}", deleted, kept));
Ed.Regen();
Result
Log
drawing: C:\Users\sanja\OneDrive\_SurveyDisco\260613 - 5030 E Lake Pkwy, Stockbridge, GA 30281, USA\260612-C-Store Sewer As-Built 60 EASEMENT PLAT LEGAL.dwg V-NODE*/V-CTRL* layers: 23 moved 6 in-block guts to 0 deleted 23, kept 0
Notes
What worked, what didn't, job-specific gotchas — flagged notes feed the recipes.
No notes yet.