C3D-LBL479 · Label the 479->506 line (bearing/distance) error
Labels the existing SS-V-LINE line; logs styles found, adds one if empty.
C# payload
// Label the existing 479->506 line (on SS-V-LINE) with a Bearing+Distance segment label.
// API verified from docs/api/AeccDbMgd.md:
// Styles.LabelStyles.GeneralLineLabelStyles : LabelStyleCollection (StyleCollectionBase -> GetEnumerator, Item, Add(name))
// GeneralSegmentLabel.Create(featureId, ratio, lineLabelStyleId, curveLabelStyleId)
// Earlier "value not in expected range" was a NULL styleId (empty collection). Now: if empty, Add() one.
var bt = (BlockTable)Tx.GetObject(Db.BlockTableId, OpenMode.ForRead);
var ms = (BlockTableRecord)Tx.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead);
// find the line we drew: on SS-V-LINE, ~154.07 long
ObjectId lineId = ObjectId.Null;
foreach (ObjectId id in ms) {
var o = Tx.GetObject(id, OpenMode.ForRead);
if (o is Line l && l.Layer == "SS-V-LINE" && System.Math.Abs(l.Length - 154.07) < 0.5) { lineId = id; break; }
}
if (lineId.IsNull) { Log("SS-V-LINE 479->506 line not found — draw it first (C3D-LINEONLY)."); return; }
var cd = CivilDoc;
var coll = cd.Styles.LabelStyles.GeneralLineLabelStyles;
// count what's there
int n = 0; ObjectId styleId = ObjectId.Null; string picked = "";
try {
var en = coll.GetEnumerator();
while (en.MoveNext()) {
n++;
var sid = (ObjectId)en.Current;
var st = (Autodesk.Civil.DatabaseServices.Styles.LabelStyle)Tx.GetObject(sid, OpenMode.ForRead);
Log($" line style: '{st.Name}'");
if (styleId.IsNull && st.Name.IndexOf("Bearing", System.StringComparison.OrdinalIgnoreCase) >= 0)
{ styleId = sid; picked = st.Name; }
if (styleId.IsNull) { styleId = sid; picked = st.Name; } // first as fallback
}
} catch (System.Exception e) { Log("enumerate failed: " + e.Message); }
Log($"GeneralLineLabelStyles count={n}");
// if none exist, create one
if (styleId.IsNull) {
styleId = coll.Add("Bearing and Distance");
picked = "Bearing and Distance (created)";
Log("no line label styles existed — added one.");
}
var labId = Autodesk.Civil.DatabaseServices.GeneralSegmentLabel.Create(lineId, 0.5, styleId, ObjectId.Null);
var lab = (Autodesk.Civil.DatabaseServices.GeneralSegmentLabel)Tx.GetObject(labId, OpenMode.ForRead);
Log($"labeled line with style '{picked}' at midpoint (h={lab.Handle}, verified).");
Result
Log
line style: 'Slope over Distance' line style: 'New General Line Label Style' line style: 'Grade Only' line style: 'Bearing and Distance' line style: 'Distance Only' line style: 'Grid Bearing over Distance' line style: 'Slope Only' line style: 'Geodetic Bearing over Distance' line style: 'Bearing over Distance' line style: 'Grade over Distance' line style: 'Geodetic Azimuth over Distance' line style: 'Bearing Only' line style: 'Standard' line style: 'Grid Azimuth over Distance' GeneralLineLabelStyles count=14
Notes
What worked, what didn't, job-specific gotchas — flagged notes feed the recipes.
No notes yet.