← Inbox

C3D-0038 · READ-ONLY: isolate the stranded sewer easement label [SSE-LABEL-FAR] error

Measures every Civil label on the sewer/prop/easement layers against its parent feature and reports only those more than 60 ft away, with parent handle/type, distance, style and dragged state. Isolates the label that points way out from the drawing. No changes.

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

C# payload

// READ-ONLY. Which sewer-easement label is stranded far from the thing it labels?
//
// The previous dump was too long to read. This one measures each Civil label's distance from its
// PARENT feature and prints ONLY the outliers (> 60 ft), so the one "pointing way out here" is
// isolated. Also reports whether the label carries a dragged-state offset, because a label whose
// anchor is its parent will snap back when you try to drag it. No changes.
var ms = (BlockTableRecord)Tx.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(Db), OpenMode.ForRead);

int n = 0, far = 0;
foreach (ObjectId id in ms) {
    var lbl = Tx.GetObject(id, OpenMode.ForRead) as Autodesk.Civil.DatabaseServices.Label;
    if (lbl == null) continue;
    var ent = (Autodesk.AutoCAD.DatabaseServices.Entity)lbl;
    string lay = ent.Layer;
    if (!(lay.StartsWith("SS-") || lay.StartsWith("C-PROP") || lay.Contains("SEWER") || lay.Contains("EASEMENT"))) continue;
    n++;

    Point3d loc;
    try { loc = lbl.LabelLocation; } catch { continue; }

    // where is the parent?
    Point3d anchor = loc; string ptype = "?"; string phandle = "?";
    double d = -1.0;
    try {
        var par = Tx.GetObject(lbl.FeatureId, OpenMode.ForRead);
        ptype = par.GetType().Name;
        phandle = par.Handle.ToString();
        var pent = par as Autodesk.AutoCAD.DatabaseServices.Entity;
        if (pent != null) {
            var e = pent.GeometricExtents;
            anchor = new Point3d((e.MinPoint.X + e.MaxPoint.X) / 2.0,
                                 (e.MinPoint.Y + e.MaxPoint.Y) / 2.0, 0.0);
            d = Math.Sqrt(Math.Pow(loc.X - anchor.X, 2) + Math.Pow(loc.Y - anchor.Y, 2));
        }
    } catch { }

    if (d < 60.0) continue;   // sitting on its parent - not the problem
    far++;
    Log("");
    Log(String.Format("STRANDED [{0}] {1}  layer={2}", ent.ObjectId.Handle, lbl.GetType().Name, lay));
    Log(String.Format("   label at  {0:F2},{1:F2}", loc.X, loc.Y));
    Log(String.Format("   parent    [{0}] {1} centre {2:F2},{3:F2}   DISTANCE {4:F1} ft", phandle, ptype, anchor.X, anchor.Y, d));
    try { Log("   style     " + lbl.StyleName); } catch { }
    try { Log("   dragged   " + lbl.IsLabelDragged); } catch (System.Exception ex) { Log("   dragged?  " + ex.Message); }
    try { Log("   visible   " + ent.Visible); } catch { }
}
Log("");
Log("civil labels on sewer/prop/easement layers: " + n + "   stranded (>60ft from parent): " + far);

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,37): error CS1061: 'Label' does not contain a definition for 'IsLabelDragged' and no accessible extension method 'IsLabelDragged' accepting a first argument of type 'Label' could be found (are you missing a using directive or an assembly reference?)
Entities
Duration
604 ms
Civil 3D
25.0.0.0

Notes

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

No notes yet.