← Inbox

C3D-0330 · Read the actual text of every segment label (explode to MText) + list open drawings [C3D-PSL4] error

Read-only. Explodes each ParcelSegmentLabel in memory to read the text it displays, so the 408.70 / 79.34 / 1089.00 / 150.35 labels can be matched by handle. Also lists every open drawing in the session.

Script file
C3D-0330.cs
Target
260714 - 285 Huckaby Rd R2.dwg · model space
Author
claude
Approved
yes · auto-auth
Timeout
120s

C# payload

Log("drawing: " + Db.Filename);
Log("open drawings:");
foreach (Autodesk.AutoCAD.ApplicationServices.Document d in
         Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager)
    Log("   " + d.Name);
Log("");

var ms = (BlockTableRecord)Tx.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(Db), OpenMode.ForRead);

// Explode each label to read what it actually says on screen.
int n = 0;
foreach (ObjectId id in ms) {
    var obj = Tx.GetObject(id, OpenMode.ForRead);
    string cls = obj.GetType().Name;
    if (cls != "ParcelSegmentLabel" && cls != "GeneralSegmentLabel") continue;
    var ent = (Autodesk.AutoCAD.DatabaseServices.Entity)obj;
    n++;

    var parts = new DBObjectCollection();
    string txt = "";
    try {
        ent.Explode(parts);
        foreach (DBObject p in parts) {
            var m = p as MText; var d = p as DBText;
            if (m != null) txt += " | " + m.Contents;
            else if (d != null) txt += " | " + d.TextString;
        }
    } catch (System.Exception e) { txt = "<explode: " + e.Message + ">"; }
    if (txt.StartsWith(" | ")) txt = txt.Substring(3);
    txt = txt.Replace("\n"," ").Replace("\r","");
    if (txt.Length > 160) txt = txt.Substring(0,160) + "...";

    Log(string.Format("[{0}] {1,-20} layer={2,-18} \"{3}\"", ent.Handle, cls, ent.Layer, txt));
}
Log("");
Log("segment labels: " + n);

Result

Status
error
Drawing file
C:\Users\sanja\OneDrive\_SurveyDisco\260714 - 285 Huckaby Rd, Brooks, GA 30205, USA\260714 - 285 Huckaby Rd R2.dwg
Message
Compile error: (23,18): error CS0104: 'DBObject' is an ambiguous reference between 'Autodesk.AutoCAD.DatabaseServices.DBObject' and 'Autodesk.Civil.DatabaseServices.DBObject'
Entities
Duration
570 ms
Civil 3D
25.0.0.0

Notes

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

No notes yet.