C3D-HCWA-SEWER · HCWA migration 1/5: sewer layers done
Move manholes/pipes/easements to exact HCWA layers; split V-SSWR-TEXT into SEWER_MANHOLE_TEXT vs SEWER_LINE_TEXT
C# payload
// HCWA migration 1/5: SEWER. Move manholes/pipes/easements onto exact HCWA layers, and SPLIT
// V-SSWR-TEXT into SEWER_MANHOLE_TEXT (structure IDs + rim/invert) vs SEWER_LINE_TEXT (run
// length/slope). Idempotent: entities already on the target layer are left alone.
var bt = (BlockTable)Tx.GetObject(Db.BlockTableId, OpenMode.ForRead);
var ms = (BlockTableRecord)Tx.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead);
var lt = (LayerTable)Tx.GetObject(Db.LayerTableId, OpenMode.ForRead);
string[] need = { "SEWER_MANHOLE","SEWER_LINE","SEWER_MANHOLE_TEXT","SEWER_LINE_TEXT",
"SEWER_EASEMENT","SEWER_EASEMENT_TEXT" };
foreach (var n in need) if (!lt.Has(n)) { Log($"ABORT: layer '{n}' missing — run C3D-HCWALAYERS first."); return; }
var move = new List<(ObjectId id, string to, string why)>();
foreach (ObjectId id in ms) {
var o = Tx.GetObject(id, OpenMode.ForRead);
var e = o as Autodesk.AutoCAD.DatabaseServices.Entity;
if (e == null) continue;
if (e.Layer == "V-SSWR-MHOL" && o is Circle)
move.Add((id, "SEWER_MANHOLE", "manhole circle"));
else if (e.Layer == "V-SSWR-PIPE" && (o is Line || o is Polyline))
move.Add((id, "SEWER_LINE", "sewer tangent"));
else if (e.Layer == "V-SSWR-TEXT" && o is DBText t) {
var s = (t.TextString ?? "").Trim().ToUpperInvariant();
// structure text: "SSMH 1105", "R733.76 I721.54" | line text: "131' --", "9' 8.0%"
bool isStruct = s.StartsWith("SSMH") || s.StartsWith("R") && s.Contains("I");
move.Add((id, isStruct ? "SEWER_MANHOLE_TEXT" : "SEWER_LINE_TEXT",
isStruct ? "structure label" : "run length/slope"));
}
else if (e.Layer == "V-ESMT-SSE20") {
if (o is DBText) move.Add((id, "SEWER_EASEMENT_TEXT", "easement label"));
else if (o is Polyline || o is Line) move.Add((id, "SEWER_EASEMENT", "easement line"));
}
}
int moved = 0;
var tally = new Dictionary<string,int>();
foreach (var (id, to, why) in move) {
var e = (Autodesk.AutoCAD.DatabaseServices.Entity)Tx.GetObject(id, OpenMode.ForWrite);
if (e.Layer == to) continue;
string from = e.Layer;
e.Layer = to;
var chk = (Autodesk.AutoCAD.DatabaseServices.Entity)Tx.GetObject(id, OpenMode.ForRead);
if (chk.Layer != to) { Log($" FAILED {from} -> {to}"); continue; }
tally[to] = tally.TryGetValue(to, out var n) ? n+1 : 1;
moved++;
}
foreach (var kv in tally.OrderBy(k => k.Key)) Log($" -> {kv.Key}: {kv.Value} entities (verified)");
Log($"SEWER migration: {moved} entities moved onto HCWA layers.");
Result
Log
-> SEWER_EASEMENT: 4 entities (verified) -> SEWER_EASEMENT_TEXT: 1 entities (verified) -> SEWER_LINE: 8 entities (verified) -> SEWER_LINE_TEXT: 7 entities (verified) -> SEWER_MANHOLE: 8 entities (verified) -> SEWER_MANHOLE_TEXT: 16 entities (verified) SEWER migration: 44 entities moved onto HCWA layers.
Notes
What worked, what didn't, job-specific gotchas — flagged notes feed the recipes.
No notes yet.