C3D-0072 · READ-ONLY: true length and named endpoints of every sewer segment [SEG-LENGTHS] done
Reports every line and polyline on a sewer layer with its measured length and both endpoints, naming the nearest survey point at each end, so the user CSV segment table can be matched against real drawing geometry rather than an assumed mapping. No changes.
C# payload
// READ-ONLY. Every sewer segment in the drawing with its true length and endpoints, and which
// survey point (if any) sits at each end. This is the ground truth to match the user's table
// against - I will not assume the earlier mapping was right, two of its rows disagreed on distance.
//
// Reports EVERY line/polyline on SEWER_LINE (and any sewer-ish layer), not just the 14 I labelled,
// in case a segment exists that I never mapped.
var ms = (BlockTableRecord)Tx.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(Db), OpenMode.ForRead);
Func<Func<string>, string> safe = f => { try { return f(); } catch (System.Exception ex) { return "<" + ex.GetType().Name + ">"; } };
// collect the manhole / sewer points so ends can be named
var pts = new List<object[]>(); // number, desc, x, y
foreach (ObjectId id in ms) {
var cp = Tx.GetObject(id, OpenMode.ForRead) as CogoPoint;
if (cp == null) continue;
string d = (safe(() => cp.RawDescription ?? "")).Trim().ToUpper();
pts.Add(new object[] { cp.PointNumber, d, cp.Easting, cp.Northing });
}
Func<double,double,string> nameAt = (x, y) => {
string best = ""; double bd = 3.0;
foreach (var p in pts) {
double dx = (double)p[2] - x, dy = (double)p[3] - y;
double dd = Math.Sqrt(dx*dx + dy*dy);
if (dd < bd) { bd = dd; best = p[0].ToString() + " " + (string)p[1]; }
}
return best.Length == 0 ? "(no point)" : best + String.Format(" [{0:F2}ft]", bd);
};
Log("=== SEWER SEGMENTS IN THE DRAWING ===");
int n = 0;
foreach (ObjectId id in ms) {
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 = safe(() => ent.Layer);
if (lay.ToUpper().IndexOf("SEWER") < 0) continue;
var ln = o as Line;
var pl = o as Polyline;
if (ln == null && pl == null) continue;
if (ln != null) {
n++;
Log("");
Log(String.Format("[{0}] Line layer={1} LENGTH={2:F2}", o.Handle, lay, ln.Length));
Log(" start " + String.Format("{0:F2},{1:F2}", ln.StartPoint.X, ln.StartPoint.Y) + " = " + nameAt(ln.StartPoint.X, ln.StartPoint.Y));
Log(" end " + String.Format("{0:F2},{1:F2}", ln.EndPoint.X, ln.EndPoint.Y) + " = " + nameAt(ln.EndPoint.X, ln.EndPoint.Y));
} else {
n++;
Log("");
Log(String.Format("[{0}] Polyline layer={1} verts={2} LENGTH={3:F2} closed={4}",
o.Handle, lay, pl.NumberOfVertices, pl.Length, pl.Closed));
for (int i = 0; i < pl.NumberOfVertices && i < 30; i++) {
var v = pl.GetPoint2dAt(i);
Log(String.Format(" v{0,-2} {1:F2},{2:F2} = {3}", i, v.X, v.Y, nameAt(v.X, v.Y)));
}
}
}
Log("");
Log("sewer line entities: " + n);
Result
Log
=== SEWER SEGMENTS IN THE DRAWING ===
[2E95F] Line layer=SEWER_LINE LENGTH=12.07
start 2296651.99,1280058.10 = 358 SSMH TEST MH [0.00ft]
end 2296651.97,1280046.04 = (no point)
[2EC86] Line layer=SEWER_LINE LENGTH=132.52
start 2296379.85,1279953.52 = 473 SSMH A16 [0.00ft]
end 2296511.25,1279951.45 = 424 SSMH A14 [0.00ft]
[2EC87] Line layer=SEWER_LINE LENGTH=133.21
start 2296511.25,1279951.45 = 424 SSMH A14 [0.00ft]
end 2296604.65,1280046.20 = 377 SSMH A12 [0.00ft]
[2EC88] Line layer=SEWER_LINE LENGTH=55.14
start 2296549.94,1280052.78 = 1132 6 IN PVC STUB [0.00ft]
end 2296604.65,1280046.20 = 377 SSMH A12 [0.00ft]
[2EC89] Line layer=SEWER_LINE LENGTH=86.31
start 2296604.65,1280046.20 = 377 SSMH A12 [0.00ft]
end 2296690.96,1280045.90 = 352 SSMH A10 [0.00ft]
[2EC8A] Line layer=SEWER_LINE LENGTH=30.97
start 2296690.96,1280045.90 = 352 SSMH A10 [0.00ft]
end 2296714.07,1280025.30 = 344 SSMH A9 [0.00ft]
[2EC8B] Line layer=SEWER_LINE LENGTH=133.46
start 2296714.07,1280025.30 = 344 SSMH A9 [0.00ft]
end 2296827.25,1280095.99 = 378 SSMH A6 [0.00ft]
[2EC8C] Line layer=SEWER_LINE LENGTH=80.46
start 2296827.25,1280095.99 = 378 SSMH A6 [0.00ft]
end 2296878.69,1280034.22 = 379 SSMH A5 [0.00ft]
[2EC8D] Line layer=SEWER_LINE LENGTH=161.58
start 2296878.69,1280034.22 = 379 SSMH A5 [0.00ft]
end 2296980.45,1279912.31 = 380 SSMH A4 [0.00ft]
[2EC8E] Line layer=SEWER_LINE LENGTH=359.02
start 2296980.45,1279912.31 = 380 SSMH A4 [0.00ft]
end 2297249.93,1279675.24 = 381 SSMH A3 [0.00ft]
[2EC8F] Line layer=SEWER_LINE LENGTH=80.02
start 2297249.93,1279675.24 = 381 SSMH A3 [0.00ft]
end 2297269.03,1279597.72 = 382 SSMH A2 [0.00ft]
[2EC90] Line layer=SEWER_LINE LENGTH=155.37
start 2297269.03,1279597.72 = 382 SSMH A2 [0.00ft]
end 2297422.96,1279618.78 = 383 SSMH A1 [0.00ft]
[2EC91] Line layer=SEWER_LINE LENGTH=19.54
start 2297422.96,1279618.78 = 383 SSMH A1 [0.00ft]
end 2297424.71,1279599.32 = 384 SSMH MAIN [0.00ft]
[2EC92] Line layer=SEWER_LINE LENGTH=8.66
start 2296685.19,1280052.35 = 353 SSMH TEST MH [0.00ft]
end 2296690.96,1280045.90 = 352 SSMH A10 [0.00ft]
[2EE30] Polyline layer=SEWER_EASEMENT POLY verts=19 LENGTH=1663.31 closed=True
v0 2296382.28,1279968.48 = (no point)
v1 2296505.07,1279966.55 = (no point)
v2 2296572.50,1280034.96 = (no point)
v3 2296533.25,1280039.67 = (no point)
v4 2296536.84,1280069.46 = (no point)
v5 2296606.44,1280061.09 = (no point)
v6 2296696.70,1280060.88 = 310 TBC [1.67ft]
v7 2296715.66,1280043.98 = (no point)
v8 2296830.40,1280115.64 = (no point)
v9 2296890.21,1280043.83 = (no point)
v10 2296991.97,1279921.92 = (no point)
v11 2296968.93,1279902.70 = (no point)
v12 2296867.17,1280024.61 = (no point)
v13 2296824.10,1280076.34 = (no point)
v14 2296712.48,1280006.62 = (no point)
v15 2296685.22,1280030.92 = 1088 TBC [1.63ft]
v16 2296610.90,1280031.18 = (no point)
v17 2296517.43,1279936.35 = (no point)
v18 2296377.81,1279938.55 = (no point)
[2EEB6] Polyline layer=SEWER_EASEMENT POLY verts=8 LENGTH=1248.48 closed=True
v0 2296988.22,1279918.79 = (no point)
v1 2297258.89,1279680.68 = (no point)
v2 2297276.59,1279608.85 = (no point)
v3 2297431.51,1279630.04 = (no point)
v4 2297434.22,1279610.23 = (no point)
v5 2297261.47,1279586.59 = (no point)
v6 2297240.97,1279669.80 = (no point)
v7 2296972.68,1279905.83 = (no point)
sewer line entities: 16Notes
What worked, what didn't, job-specific gotchas — flagged notes feed the recipes.
No notes yet.