← Inbox

C3D-0605 · Free V-NODE layers and delete them done

Inside block definitions, move every entity on a V-NODE* layer to layer 0 so it displays on its insert's layer (outer inserts untouched, HIDDEN ones included). Then delete every V-NODE* layer the purge check reports unreferenced.

Script file
C3D-0605.cs
Target
ACAD-260612-C-Store As-Built 60 H2O wPROFILE.dwg · model space
Author
claude
Approved
yes · auto-auth
Timeout
60s

C# payload

var lt=(LayerTable)Tx.GetObject(Db.LayerTableId,OpenMode.ForRead);
var vids=new Dictionary<ObjectId,string>();
foreach(ObjectId id in lt){ var lr=(LayerTableRecord)Tx.GetObject(id,OpenMode.ForRead); if(lr.Name.StartsWith("V-NODE",StringComparison.OrdinalIgnoreCase)) vids[id]=lr.Name; }
Log("V-NODE layers: "+string.Join(", ",vids.Values));
var bt=(BlockTable)Tx.GetObject(Db.BlockTableId,OpenMode.ForRead);
int moved=0, top=0; var per=new SortedDictionary<string,int>();
foreach(ObjectId sid in bt){
  var b=(BlockTableRecord)Tx.GetObject(sid,OpenMode.ForRead);
  if(b.IsFromExternalReference) continue;
  foreach(ObjectId id in b){
    var en=Tx.GetObject(id,OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Entity; if(en==null || !vids.ContainsKey(en.LayerId)) continue;
    if(b.IsLayout){ top++; Log("  TOP-LEVEL (left) "+en.GetType().Name+" h="+en.Handle+" on "+en.Layer); continue; }
    string from=en.Layer; en.UpgradeOpen(); en.LayerId=Db.LayerZero; moved++;
    string k=from+" -> 0 in "+b.Name; per[from]=per.ContainsKey(from)?per[from]+1:1;
  }
}
foreach(var kv in per) Log("  moved "+kv.Value+" from "+kv.Key+" to 0 (inside blocks; shows on the insert's layer)");
Log("moved="+moved+" top-level left="+top);
var ids=new ObjectIdCollection(); foreach(var k in vids.Keys) ids.Add(k);
Db.Purge(ids);
int del=0;
foreach(var kv in vids){
  var lr=(LayerTableRecord)Tx.GetObject(kv.Key,OpenMode.ForRead);
  if(ids.Contains(kv.Key) && kv.Key!=Db.Clayer){ lr.UpgradeOpen(); lr.Erase(); del++; Log("  deleted layer "+kv.Value); }
  else Log("  KEPT layer "+kv.Value+" (still referenced)");
}
int left=0; foreach(ObjectId id in lt){ var lr=(LayerTableRecord)Tx.GetObject(id,OpenMode.ForRead); if(!lr.IsErased && lr.Name.StartsWith("V-NODE",StringComparison.OrdinalIgnoreCase)) left++; }
Log("layers deleted="+del+" V-NODE layers remaining="+left+" (verified)");
Ed.Regen();

Result

Status
success
Drawing file
C:\Users\sanja\OneDrive\_SurveyDisco\260613 - 5030 E Lake Pkwy, Stockbridge, GA 30281, USA\REDLINE\ACAD-260612-C-Store As-Built 60 H2O wPROFILE.dwg
Message
Executed C3D-0605 (0 entities touched).
Entities
—
Duration
840 ms
Civil 3D
25.0.0.0

Log

V-NODE layers: V-NODE-TEXT, V-NODE-TREE, V-NODE-WATR, V-NODE-STRM, V-NODE-BNDY, V-NODE-POLE, V-NODE-BORE
  moved 8 from V-NODE-BNDY to 0 (inside blocks; shows on the insert's layer)
  moved 1 from V-NODE-BORE to 0 (inside blocks; shows on the insert's layer)
  moved 2 from V-NODE-POLE to 0 (inside blocks; shows on the insert's layer)
  moved 14 from V-NODE-STRM to 0 (inside blocks; shows on the insert's layer)
  moved 37 from V-NODE-TEXT to 0 (inside blocks; shows on the insert's layer)
  moved 2 from V-NODE-TREE to 0 (inside blocks; shows on the insert's layer)
  moved 32 from V-NODE-WATR to 0 (inside blocks; shows on the insert's layer)
moved=96 top-level left=0
  deleted layer V-NODE-TEXT
  deleted layer V-NODE-TREE
  deleted layer V-NODE-WATR
  deleted layer V-NODE-STRM
  deleted layer V-NODE-BNDY
  deleted layer V-NODE-POLE
  deleted layer V-NODE-BORE
layers deleted=7 V-NODE layers remaining=0 (verified)

Notes

What worked, what didn't, job-specific gotchas — flagged notes feed the recipes.

No notes yet.