← Inbox

C3D-0079 · READ-ONLY: find the curve label style behind the ARC/CHD/RAD labels [CURVE-STYLE-FIND] error

Identifies the style definition behind the four-line ARC/CHD/bearing/RAD curve labels so it can be recreated in another drawing: reports each curve label type, its style name and parent, and enumerates the parcel and general curve label style collections. No changes.

Script file
C3D-0079.cs
Target
260612 · model space
Author
claude
Approved
yes · reviewer
Timeout
240s

C# payload

// READ-ONLY. Find WHERE the curve label format lives so it can be recreated in another drawing.
//
// The four-line ARC/CHD/bearing/RAD label is an instance of a Civil label STYLE. What has to be
// captured is the style definition - its name, which style collection owns it, and the settings
// that produce the leader. Find the label, then name the style behind it.
//
// Read one curve label and report: its concrete type, its style name, and the owning collection.
// Nothing is modified.
var ms = (BlockTableRecord)Tx.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(Db), OpenMode.ForRead);
Func<Func<string>, string> safe = f => { try { return f(); } catch (System.Exception ex) { return "<" + ex.GetType().Name + ">"; } };

Log("=== curve-ish labels in model space ===");
int n = 0;
foreach (ObjectId id in ms) {
    var lbl = Tx.GetObject(id, OpenMode.ForRead) as Autodesk.Civil.DatabaseServices.Label;
    if (lbl == null) continue;
    string tn = lbl.GetType().Name;
    // curve labels: ParcelSegmentLabel on an arc, GeneralSegmentLabel, CurveLabel...
    if (tn.IndexOf("Segment") < 0 && tn.IndexOf("Curve") < 0) continue;
    n++;
    if (n > 12) continue;
    var ent = (Autodesk.AutoCAD.DatabaseServices.Entity)lbl;
    Log("");
    Log("[" + lbl.Handle + "] " + tn + "  layer=" + safe(() => ent.Layer));
    Log("    StyleName  " + safe(() => lbl.StyleName));
    Log("    StyleId    " + safe(() => lbl.StyleId.ToString()));
    try {
        var par = Tx.GetObject(lbl.FeatureId, OpenMode.ForRead);
        Log("    parent     " + par.GetType().Name + " [" + par.Handle + "]");
        var pseg = par as ParcelSegment;
        if (pseg != null) Log("    parent curve? BaseCurve=" + safe(() => pseg.BaseCurve.GetType().Name));
    } catch (System.Exception ex) { Log("    parent: " + ex.Message); }
}
Log("");
Log("total segment/curve labels: " + n);

// where the STYLE definitions live
var civil = CivilApplication.ActiveDocument;
Log("");
Log("=== label style collections ===");
try {
    var pls = civil.Styles.LabelStyles.ParcelLabelStyles;
    Log("  ParcelLabelStyles.LineLabelStyles:");
    foreach (ObjectId sid in pls.LineLabelStyles.LabelStyles)
        Log("     " + safe(() => ((Autodesk.Civil.DatabaseServices.Styles.StyleBase)Tx.GetObject(sid, OpenMode.ForRead)).Name));
    Log("  ParcelLabelStyles.CurveLabelStyles:");
    foreach (ObjectId sid in pls.CurveLabelStyles.LabelStyles)
        Log("     " + safe(() => ((Autodesk.Civil.DatabaseServices.Styles.StyleBase)Tx.GetObject(sid, OpenMode.ForRead)).Name));
} catch (System.Exception ex) { Log("  parcel label styles: " + ex.Message); }

try {
    var gls = civil.Styles.LabelStyles.GeneralLabelStyles;
    Log("  GeneralLabelStyles.CurveLabelStyles:");
    foreach (ObjectId sid in gls.CurveLabelStyles.LabelStyles)
        Log("     " + safe(() => ((Autodesk.Civil.DatabaseServices.Styles.StyleBase)Tx.GetObject(sid, OpenMode.ForRead)).Name));
} catch (System.Exception ex) { Log("  general label styles: " + ex.Message); }

Result

Status
error
Drawing file
C:\Users\sanja\OneDrive\_SurveyDisco\260613 - 5030 E Lake Pkwy, Stockbridge, GA 30281, USA\260612 - CSTORE WATER ABS 30.dwg
Message
Compile error: (44,50): error CS1061: 'LabelStyleCollection' does not contain a definition for 'LabelStyles' and no accessible extension method 'LabelStyles' accepting a first argument of type 'LabelStyleCollection' could be found (are you missing a using directive or an assembly reference?); (47,51): error CS1061: 'LabelStyleCollection' does not contain a definition for 'LabelStyles' and no accessible extension method 'LabelStyles' accepting a first argument of type 'LabelStyleCollection' could be found (are you missing a using directive or an assembly reference?); (52,40): error CS1061: 'LabelStylesRoot' does not contain a definition for 'GeneralLabelStyles' and no accessible extension method 'GeneralLabelStyles' accepting a first argument of type 'LabelStylesRoot' could be found (are you missing a using directive or an assembly reference?)
Entities
Duration
312 ms
Civil 3D
25.0.0.0

Notes

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

No notes yet.