← Inbox

C3D-LINE479 · Line 479->506 + bearing/distance label (API verified) error

Draw line pt 479 -> pt 506 on SS-V-LINE and label with a Bearing+Distance line label. API path verified from the reflected AeccDbMgd.dll (GeneralLineLabelStyles + 4-arg GeneralSegmentLabel.Create), not guessed.

Script file
C3D-LINE479.cs
Target
C:\Users\sanja\OneDrive\_SurveyDisco\260619 - 3625 Stonewall Tell Rd, Atlanta, GA 30349, USA\260619 - 3625 Stonewall Tell Rd.dwg · model space
Author
claude
Approved
yes · reviewer
Timeout
60s

C# payload

// Draw line 479->506 and label it Bearing+Distance.
// API verified from docs/api/AeccDbMgd.md (reflected from AeccDbMgd.dll — NOT guessed):
//   CivilDocument.Styles.LabelStyles.GeneralLineLabelStyles -> LabelStyleCollection
//   GeneralSegmentLabel.Create(featureId, ratio, lineLabelStyleId, curveLabelStyleId)
var bt = (BlockTable)Tx.GetObject(Db.BlockTableId, OpenMode.ForRead);
var ms = (BlockTableRecord)Tx.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

var cd = CivilDoc; var cps = cd.CogoPoints;
Point3d? a = null, b = null;
foreach (ObjectId id in cps) {
    var cp = (Autodesk.Civil.DatabaseServices.CogoPoint)Tx.GetObject(id, OpenMode.ForRead);
    if (cp.PointNumber == 479) a = new Point3d(cp.Easting, cp.Northing, 0);
    if (cp.PointNumber == 506) b = new Point3d(cp.Easting, cp.Northing, 0);
}
if (a == null || b == null) { Log("point 479 or 506 not found"); return; }

EnsureLayer("SS-V-LINE", 3);
var ln = new Line(a.Value, b.Value) { Layer = "SS-V-LINE" };
ms.AppendEntity(ln); Tx.AddNewlyCreatedDBObject(ln, true);
Log($"line 479->506 drawn len={ln.Length:F2} on SS-V-LINE (h={ln.Handle}).");

// find a "Bearing and Distance" (or "Bearing over Distance") line label style
var lineStyles = cd.Styles.LabelStyles.GeneralLineLabelStyles;
ObjectId styleId = ObjectId.Null;
string picked = "";
foreach (ObjectId sid in lineStyles) {
    var st = (Autodesk.Civil.DatabaseServices.Styles.LabelStyle)Tx.GetObject(sid, OpenMode.ForRead);
    var n = st.Name;
    if (n.IndexOf("Bearing", System.StringComparison.OrdinalIgnoreCase) >= 0
        && n.IndexOf("Distance", System.StringComparison.OrdinalIgnoreCase) >= 0) { styleId = sid; picked = n; break; }
}
// fall back to first available if no exact match, but log it
if (styleId.IsNull) {
    foreach (ObjectId sid in lineStyles) {
        var st = (Autodesk.Civil.DatabaseServices.Styles.LabelStyle)Tx.GetObject(sid, OpenMode.ForRead);
        styleId = sid; picked = st.Name + " (fallback — no Bearing+Distance style found)"; break;
    }
}
if (styleId.IsNull) { Log("no line label styles exist in the drawing — line drawn, label skipped."); return; }

// Create(featureId, ratio 0..1, lineLabelStyleId, curveLabelStyleId). 0.5 = midpoint. No curve => Null.
var labId = Autodesk.Civil.DatabaseServices.GeneralSegmentLabel.Create(ln.ObjectId, 0.5, styleId, ObjectId.Null);
var lab = (Autodesk.Civil.DatabaseServices.GeneralSegmentLabel)Tx.GetObject(labId, OpenMode.ForRead);
Log($"labeled with style '{picked}' at midpoint (h={lab.Handle}, verified).");

Result

Status
error
Drawing file
C:\Users\sanja\OneDrive\_SurveyDisco\260619 - 3625 Stonewall Tell Rd, Atlanta, GA 30349, USA\260619 - 3625 Stonewall Tell Rd.dwg
Message
Value does not fall within the expected range.
Entities
Duration
396 ms
Civil 3D
25.0.0.0

Log

line 479->506 drawn len=154.07 on SS-V-LINE (h=20E8A).

Notes

What worked, what didn't, job-specific gotchas — flagged notes feed the recipes.

No notes yet.