← Inbox

C3D-0011 · Read notes near point 424 [NOTE-424] error

Read-only: all NoteLabels with their text and distance to point 424, plus leaders/mleaders/text within 400ft of it.

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

C# payload

// READ-ONLY: every NoteLabel / MLeader / text near point 424 (2296511.25,1279951.45), with its
// content and where it points, so the note that references that manhole can be read in full.
const double PX = 2296511.25, PY = 1279951.45;
const double R = 400.0;   // search radius, ft

double D(double x, double y) { return System.Math.Sqrt((x-PX)*(x-PX) + (y-PY)*(y-PY)); }

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

Log("=== NoteLabels (all - there are only a few) ===");
foreach (ObjectId id in ms)
{
    var nl = Tx.GetObject(id, OpenMode.ForRead) as Autodesk.Civil.DatabaseServices.NoteLabel;
    if (nl == null) continue;
    var p = nl.Location;
    var txt = new List<string>();
    try {
        foreach (ObjectId tid in nl.GetTextComponentIds())
            txt.Add(nl.GetTextComponentOverride(tid));
    } catch (System.Exception ex) { txt.Add("(components: " + ex.Message + ")"); }
    Log("  NoteLabel h=" + nl.Handle + " layer='" + nl.Layer + "' style='" + nl.StyleName + "'");
    Log("      at (" + p.X.ToString("F2") + "," + p.Y.ToString("F2") + ")  dist to pt424 = " + D(p.X,p.Y).ToString("F1") + " ft");
    foreach (var t in txt) if (!string.IsNullOrEmpty(t)) Log("      text: " + t.Replace("\u005CP", " | "));
}

Log("=== leaders / mleaders and text within " + R + " ft of pt 424 ===");
foreach (ObjectId id in ms)
{
    var e = Tx.GetObject(id, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Entity;
    if (e == null) continue;

    var ml = e as MLeader;
    if (ml != null) {
        var p = ml.MText != null ? ml.MText.Location : Point3d.Origin;
        if (D(p.X, p.Y) > R) continue;
        Log("  MLEADER h=" + e.Handle + " layer='" + e.Layer + "' dist=" + D(p.X,p.Y).ToString("F1"));
        if (ml.MText != null) Log("      " + ml.MText.Contents.Replace("\u005CP", " | "));
        continue;
    }
    var ld = e as Leader;
    if (ld != null) {
        var p = ld.StartPoint;
        if (D(p.X, p.Y) > R && D(ld.EndPoint.X, ld.EndPoint.Y) > R) continue;
        Log("  LEADER h=" + e.Handle + " layer='" + e.Layer + "' (" + ld.StartPoint.X.ToString("F2") + "," +
            ld.StartPoint.Y.ToString("F2") + ") -> (" + ld.EndPoint.X.ToString("F2") + "," + ld.EndPoint.Y.ToString("F2") + ")");
        continue;
    }
    var mt = e as MText;
    if (mt != null && D(mt.Location.X, mt.Location.Y) <= R) {
        Log("  MTEXT h=" + e.Handle + " layer='" + e.Layer + "' dist=" + D(mt.Location.X,mt.Location.Y).ToString("F1") +
            "  " + mt.Contents.Replace("\u005CP", " | "));
        continue;
    }
    var dt = e as DBText;
    if (dt != null && D(dt.Position.X, dt.Position.Y) <= R) {
        Log("  DBTEXT h=" + e.Handle + " layer='" + e.Layer + "' dist=" + D(dt.Position.X,dt.Position.Y).ToString("F1") +
            "  '" + dt.TextString + "'");
    }
}

Result

Status
error
Drawing file
C:\Users\sanja\OneDrive\_SurveyDisco\260613 - 5030 E Lake Pkwy, Stockbridge, GA 30281, USA\260612 - CSTORE WATER ABS BOUNDARY.dwg
Message
Compile error: (15,16): error CS1061: 'NoteLabel' does not contain a definition for 'Location' and no accessible extension method 'Location' accepting a first argument of type 'NoteLabel' could be found (are you missing a using directive or an assembly reference?)
Entities
Duration
351 ms
Civil 3D
25.0.0.0

Notes

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

No notes yet.