C3D-PIPETYPE · Add pipe types under grade labels done
6 pipe-type texts 7ft under their distance/grade labels: 60' PVC/20' DIP, 60' DIP/100' PVC, PVC, DIP, PVC, PVC. Same style, horizontal.
C# payload
// Add pipe-type text UNDER each distance/grade label (7' below, same style/height, horizontal).
// Matched by the grade label's exact text on SEWER_LINE_TEXT. Idempotent.
using System;
using System.Collections.Generic;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
var types = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{
["80' 15.8%"] = "60' PVC / 20' DIP",
["159' 12.4%"] = "60' DIP / 100' PVC",
["359' 1.1%"] = "PVC",
["80' 0.6%"] = "DIP",
["155' 0.7%"] = "PVC",
["20' 0.8%"] = "PVC",
};
// existing text on the layer (for idempotency by position + finding the grade labels)
var labels = new List<DBText>();
var positions = new List<Point3d>();
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))
{
labels.Add(t);
positions.Add(t.Position);
}
}
int added = 0;
foreach (var t in labels)
{
if (!types.TryGetValue(t.TextString, out var pipeType)) continue;
var target = new Point3d(t.Position.X, t.Position.Y - 7.0, t.Position.Z);
bool occupied = false;
foreach (var p in positions) if (p.DistanceTo(target) < 1.0) { occupied = true; break; }
if (occupied) { Log($" skip under '{t.TextString}' (text already there)"); continue; }
var clone = (DBText)t.Clone();
clone.TextString = pipeType;
clone.Position = target;
if (clone.Justify != AttachmentPoint.BaseLeft)
clone.AlignmentPoint = new Point3d(t.AlignmentPoint.X, t.AlignmentPoint.Y - 7.0, t.AlignmentPoint.Z);
clone.Rotation = 0;
ModelSpace.AppendEntity(clone);
Tx.AddNewlyCreatedDBObject(clone, true);
positions.Add(target);
Log($" + '{pipeType}' under '{t.TextString}'");
added++;
}
Log($"DONE. {added} pipe-type labels added on SEWER_LINE_TEXT.");
Result
Log
+ '60' PVC / 20' DIP' under '80' 15.8%' + '60' DIP / 100' PVC' under '159' 12.4%' + 'PVC' under '359' 1.1%' + 'DIP' under '80' 0.6%' + 'PVC' under '155' 0.7%' + 'PVC' under '20' 0.8%' DONE. 6 pipe-type labels added on SEWER_LINE_TEXT.
Notes
What worked, what didn't, job-specific gotchas — flagged notes feed the recipes.
No notes yet.