C3D-0105 · Move everything on SS- layers to layer 0 [SS-TO-ZERO] done
Moves every entity on any SS- prefixed layer to layer 0 across model space, paper space and block definitions. Frozen and locked SS- layers are thawed first so nothing is skipped. The layers themselves are kept; nothing is erased. Verifies no entities remain on an SS- layer.
C# payload
// Move every entity on an SS-* layer to layer 0.
// Covers model space, paper space and block definitions. The SS- layers themselves are left in
// place (empty) - nothing is erased.
var lt = (LayerTable)Tx.GetObject(Db.LayerTableId, OpenMode.ForRead);
var bt = (BlockTable)Tx.GetObject(Db.BlockTableId, OpenMode.ForRead);
Log("drawing: " + Db.Filename);
var ss = new HashSet<string>();
foreach (ObjectId lid in lt) {
var l = (LayerTableRecord)Tx.GetObject(lid, OpenMode.ForRead);
if (l.Name.ToUpper().StartsWith("SS-")) ss.Add(l.Name);
}
Log("SS- layers: " + ss.Count);
foreach (var n in ss) Log(" " + n);
// thaw/unlock so the move cannot silently skip anything
foreach (string nm in ss) {
var l = (LayerTableRecord)Tx.GetObject(lt[nm], OpenMode.ForWrite);
if (l.IsFrozen) l.IsFrozen = false;
if (l.IsLocked) l.IsLocked = false;
if (l.IsOff) l.IsOff = false;
}
var moved = new Dictionary<string,int>();
int total = 0;
foreach (ObjectId btrId in bt) {
var btr = (BlockTableRecord)Tx.GetObject(btrId, OpenMode.ForRead);
foreach (ObjectId id in btr) {
Autodesk.AutoCAD.DatabaseServices.DBObject o;
try { o = Tx.GetObject(id, OpenMode.ForRead); } catch { continue; }
var ent = o as Autodesk.AutoCAD.DatabaseServices.Entity;
if (ent == null) continue;
string lay; try { lay = ent.Layer; } catch { continue; }
if (!ss.Contains(lay)) continue;
try {
var w = (Autodesk.AutoCAD.DatabaseServices.Entity)Tx.GetObject(id, OpenMode.ForWrite);
w.Layer = "0";
if (!moved.ContainsKey(lay)) moved[lay] = 0;
moved[lay]++;
total++;
} catch (System.Exception ex) { Log(" could not move " + id.Handle + ": " + ex.Message); }
}
}
Log("");
foreach (var kv in moved) Log(" " + kv.Key + " -> 0 : " + kv.Value);
Log("entities moved to layer 0: " + total);
// verify nothing is left on any SS- layer
int leftover = 0;
foreach (ObjectId btrId in bt) {
var btr = (BlockTableRecord)Tx.GetObject(btrId, OpenMode.ForRead);
foreach (ObjectId id in btr) {
Autodesk.AutoCAD.DatabaseServices.DBObject o;
try { o = Tx.GetObject(id, OpenMode.ForRead); } catch { continue; }
var ent = o as Autodesk.AutoCAD.DatabaseServices.Entity;
if (ent == null) continue;
try { if (ss.Contains(ent.Layer)) leftover++; } catch { }
}
}
Log("entities still on an SS- layer: " + leftover + " (verified)");
Ed.Regen();
Result
Log
drawing: C:\Users\sanja\OneDrive\_SurveyDisco\260613 - 5030 E Lake Pkwy, Stockbridge, GA 30281, USA\ACAD-260612 - CSTORE WATER ABS 30.dwg SS- layers: 5 SS-ROAD-STRIPE SS-ROAD-SIDEWALK SS-ROAD-BUILDING SS-ROAD-DUMPSTER SS-ROAD-CANOPY SS-ROAD-SIDEWALK -> 0 : 2 SS-ROAD-BUILDING -> 0 : 1 SS-ROAD-DUMPSTER -> 0 : 1 SS-ROAD-CANOPY -> 0 : 1 SS-ROAD-STRIPE -> 0 : 40 entities moved to layer 0: 45 entities still on an SS- layer: 0 (verified)
Notes
What worked, what didn't, job-specific gotchas — flagged notes feed the recipes.
No notes yet.