C3D-ESMTMAP · Map SS-ESMT-SSE20 to SEWER_EASEMENT done
Moves the 20ft sanitary sewer easement Site/ParcelSegment onto the HCWA SEWER_EASEMENT layer, and reports the final layer usage. Civil 3D parcel objects may be style-driven, so the script verifies whether the change stuck.
C# payload
// Map the remaining original layers onto their HCWA equivalents.
// SS-ESMT-SSE20 (20' sanitary sewer easement) -> SEWER_EASEMENT.
// NOTE: these are Civil 3D Site/ParcelSegment objects; their layer may be driven by the parcel
// style rather than the entity, so this reads back and reports whether the change actually stuck.
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);
if (!lt.Has("SEWER_EASEMENT")) { Log("ABORT: SEWER_EASEMENT layer missing."); return; }
var targets = new List<ObjectId>();
foreach (ObjectId id in ms) {
var e = Tx.GetObject(id, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Entity;
if (e != null && e.Layer == "SS-ESMT-SSE20") targets.Add(id);
}
Log($"entities on SS-ESMT-SSE20: {targets.Count}");
int ok = 0, stuck = 0;
foreach (var id in targets) {
var e = (Autodesk.AutoCAD.DatabaseServices.Entity)Tx.GetObject(id, OpenMode.ForWrite);
string type = e.GetType().Name, from = e.Layer;
try { e.Layer = "SEWER_EASEMENT"; }
catch (System.Exception ex) { Log($" {type}: set failed - {ex.Message}"); stuck++; continue; }
var chk = (Autodesk.AutoCAD.DatabaseServices.Entity)Tx.GetObject(id, OpenMode.ForRead);
if (chk.Layer == "SEWER_EASEMENT") { Log($" {type}: '{from}' -> 'SEWER_EASEMENT' (verified)"); ok++; }
else { Log($" {type}: did NOT stick, still on '{chk.Layer}' (style-driven)"); stuck++; }
}
Log($"moved: {ok}, would not move: {stuck}");
// report the final state of every layer still holding geometry
Log("--- layers still in use ---");
var tally = new Dictionary<string,int>();
foreach (ObjectId id in ms) {
var e = Tx.GetObject(id, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Entity;
if (e == null) continue;
tally[e.Layer] = tally.TryGetValue(e.Layer, out var n) ? n+1 : 1;
}
foreach (var kv in tally.OrderBy(k => k.Key)) Log($" {kv.Key,-28} {kv.Value}");
Result
Log
entities on SS-ESMT-SSE20: 2 Site: 'SS-ESMT-SSE20' -> 'SEWER_EASEMENT' (verified) ParcelSegment: 'SS-ESMT-SSE20' -> 'SEWER_EASEMENT' (verified) moved: 2, would not move: 0 --- layers still in use --- 0 85 FIRE_HYDRANT 2 FIRE_HYDRANT_TEXT 3 FIRE_HYDRANT_VALVE 2 PDF_IMPORT_ASBUILT 1 ROAD_EDGE_OF_PAVEMENT 1 ROAD_TEXT 1 SEWER_EASEMENT 3 SEWER_EASEMENT_TEXT 1 SEWER_LINE 12 SEWER_LINE_TEXT 7 SEWER_MANHOLE 10 SEWER_MANHOLE_TEXT 20 SS-FRZ 58 SS-GREASE 4 SS-V-ROAD-CURB 6 V-GREASE 8 V-STRM-STRC 9 V-STRM-TEXT 20 V-WATR-STRC 1 WATER_END_CAP 1 WATER_LINE 4 WATER_LINE_TEXT 11 WATER_SERVICE 6 WATER_VALVE 1 WATER_VALVE_TEXT 5 WATER_VAULT 2 WATER_VAULT_TEXT 4
Notes
What worked, what didn't, job-specific gotchas — flagged notes feed the recipes.
No notes yet.