C3D-SEWERDIST · Get real sewer segment distances (read-only) done
Walk SEWER_LINE geometry, match endpoints to nearest 7000s SSMH point, report real lengths for flow % calc.
C# payload
// READ-ONLY: get real distances between the 7000-series SSMH points, from the actual SEWER_LINE
// geometry (not straight-line point-to-point, since sewer runs can bend). Report each segment's
// endpoints (nearest point number) and length.
using System;
using System.Linq;
using System.Collections.Generic;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.Civil.ApplicationServices;
using Autodesk.Civil.DatabaseServices;
var db = Db;
// load the 7000s points into a lookup: number -> (E,N)
var pts = new Dictionary<int, Point2d>();
var cdoc = CivilDocument.GetCivilDocument(db);
using (var tr = db.TransactionManager.StartTransaction())
{
foreach (ObjectId id in cdoc.CogoPoints)
{
var cp = tr.GetObject(id, OpenMode.ForRead) as CogoPoint;
if (cp == null) continue;
int n = (int)cp.PointNumber;
if (n >= 7000 && n <= 7013) pts[n] = new Point2d(cp.Easting, cp.Northing);
}
tr.Commit();
}
Log($"loaded {pts.Count} SSMH points");
int NearestPoint(Point2d p)
{
int best = -1; double bd = 30; // within 30ft = "at this manhole"
foreach (var kv in pts)
{
double d = p.GetDistanceTo(kv.Value);
if (d < bd) { bd = d; best = kv.Key; }
}
return best;
}
// walk SEWER_LINE geometry (Polylines) and report each segment's endpoints -> nearest points + length
using (var tr = db.TransactionManager.StartTransaction())
{
var ms = (BlockTableRecord)tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForRead);
int found = 0;
foreach (ObjectId id in ms)
{
var e = tr.GetObject(id, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Entity;
if (e == null || !string.Equals(e.Layer, "SEWER_LINE", StringComparison.OrdinalIgnoreCase)) continue;
if (e is Polyline pl)
{
found++;
double totalLen = pl.Length;
var start = new Point2d(pl.GetPoint2dAt(0).X, pl.GetPoint2dAt(0).Y);
var end = new Point2d(pl.GetPoint2dAt(pl.NumberOfVertices-1).X, pl.GetPoint2dAt(pl.NumberOfVertices-1).Y);
int a = NearestPoint(start), b = NearestPoint(end);
Log($"SEWER_LINE polyline h={e.Handle}: {a} -> {b} length={totalLen:0.00} ft verts={pl.NumberOfVertices}");
}
else if (e is Line ln)
{
found++;
var start = new Point2d(ln.StartPoint.X, ln.StartPoint.Y);
var end = new Point2d(ln.EndPoint.X, ln.EndPoint.Y);
int a = NearestPoint(start), b = NearestPoint(end);
Log($"SEWER_LINE line h={e.Handle}: {a} -> {b} length={ln.Length:0.00} ft");
}
}
Log($"total SEWER_LINE geometry entities: {found}");
tr.Commit();
}
Result
Log
loaded 14 SSMH points SEWER_LINE polyline h=9A: 7007 -> 7013 length=853.03 ft verts=7 total SEWER_LINE geometry entities: 1
Notes
What worked, what didn't, job-specific gotchas — flagged notes feed the recipes.
No notes yet.