C3D-SEGLABELS · Add distance+grade labels on 6 sewer segments done
Plan-view DBText per segment ('159 12.4%' style) at midpoint, rotated along pipe, 10ft offset, SEWER_LINE_TEXT, height matched to MH labels. Final worksheet values. Pipe types left for user.
C# payload
// Add distance + grade labels on each sewer segment in PLAN view (format like the design eg: "159' 12.4%").
// - one DBText per segment at the midpoint, rotated along the pipe (kept upright), offset 10' perpendicular
// - layer SEWER_LINE_TEXT (HCWA: sewer line text layer), height/style cloned from the manhole labels
// - values from the FINAL worksheet (Rim F3, corrected inverts, A-1 rim 687.07)
// Pipe types not included (unknown) — user adds those. Idempotent: skips labels already present.
using System;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
// segment: from(x,y), to(x,y), label
var segs = new (double x1, double y1, double x2, double y2, string label)[]
{
(2296827.2974, 1280096.1071, 2296878.6992, 1280034.2288, "80' 15.8%"), // 7007 A6 -> 7008 A5
(2296878.6992, 1280034.2288, 2296980.3753, 1279912.0813, "159' 12.4%"), // 7008 A5 -> 7009 A4
(2296980.3753, 1279912.0813, 2297249.9378, 1279675.2908, "359' 1.1%"), // 7009 A4 -> 7010 A3
(2297249.9378, 1279675.2908, 2297269.0965, 1279597.6123, "80' 0.6%"), // 7010 A3 -> 7011 A2
(2297269.0965, 1279597.6123, 2297423.0090, 1279618.6604, "155' 0.7%"), // 7011 A2 -> 7012 A1
(2297423.0090, 1279618.6604, 2297424.7637, 1279599.2288, "20' 0.8%"), // 7012 A1 -> 7013
};
EnsureLayer("SEWER_LINE_TEXT", 7);
// clone height/style from an existing manhole label (handle 9D = "R 724.74")
var tmplId = Db.GetObjectId(false, new Handle(Convert.ToInt64("9D", 16)), 0);
var tmpl = (DBText)Tx.GetObject(tmplId, OpenMode.ForRead);
// existing labels on the layer (idempotency)
var existing = new System.Collections.Generic.HashSet<string>(StringComparer.OrdinalIgnoreCase);
foreach (ObjectId id in ModelSpace)
{
var e = Tx.GetObject(id, OpenMode.ForRead);
if (e is DBText t && string.Equals(t.Layer, "SEWER_LINE_TEXT", StringComparison.OrdinalIgnoreCase))
existing.Add(t.TextString);
}
int added = 0;
foreach (var s in segs)
{
if (existing.Contains(s.label)) { Log($" skip '{s.label}' (already present)"); continue; }
double mx = (s.x1 + s.x2) / 2.0, my = (s.y1 + s.y2) / 2.0;
double ang = Math.Atan2(s.y2 - s.y1, s.x2 - s.x1);
if (ang > Math.PI / 2 || ang < -Math.PI / 2) ang += Math.PI; // keep text upright
// offset 10' perpendicular (to the upper-left of the reading direction)
double ox = -Math.Sin(ang) * 10.0, oy = Math.Cos(ang) * 10.0;
var txt = new DBText();
txt.SetDatabaseDefaults();
txt.TextString = s.label;
txt.Position = new Point3d(mx + ox, my + oy, 0);
txt.Height = tmpl.Height;
txt.TextStyleId = tmpl.TextStyleId;
txt.Rotation = ang;
txt.Layer = "SEWER_LINE_TEXT";
ModelSpace.AppendEntity(txt);
Tx.AddNewlyCreatedDBObject(txt, true);
Log($" + '{s.label}' at ({mx + ox:0.0},{my + oy:0.0}) rot={ang * 180 / Math.PI:0.0}deg");
added++;
}
Log($"DONE. {added} segment labels added on SEWER_LINE_TEXT (height {tmpl.Height:0.00}, matched to MH text). Positions are draft — nudge as needed.");
Result
Log
+ '80' 15.8%' at (2296860.7,1280071.6) rot=-50.3deg + '159' 12.4%' at (2296937.2,1279979.6) rot=-50.2deg + '359' 1.1%' at (2297121.8,1279801.2) rot=-41.3deg + '80' 0.6%' at (2297269.2,1279638.8) rot=-76.1deg + '155' 0.7%' at (2297344.7,1279618.0) rot=7.8deg + '20' 0.8%' at (2297433.8,1279609.8) rot=-84.8deg DONE. 6 segment labels added on SEWER_LINE_TEXT (height 5.50, matched to MH text). Positions are draft — nudge as needed.
Notes
What worked, what didn't, job-specific gotchas — flagged notes feed the recipes.
No notes yet.