← Inbox

C3D-LBL479 · Label the 479->506 line (bearing/distance) error

Labels the existing SS-V-LINE line; logs styles found, adds one if empty.

Script file
C3D-LBL479.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

// 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

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
378 ms
Civil 3D
25.0.0.0

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.