← Inbox

C3D-VICFIND · Locate VICINITY MAP text in paper space (read-only) error

Find the vicinity map label + any existing raster images so the map can be placed above it

Script file
C3D-VICFIND.cs
Target
active document · model space
Author
claude
Approved
yes · claude (read-only inspection)
Timeout
60s

C# payload

// Read-only: locate "VICINITY MAP" text in paper space + report its position/height and the
// empty area above it, so a raster image can be placed correctly.
var bt = (BlockTable)Tx.GetObject(Db.BlockTableId, OpenMode.ForRead);
foreach (ObjectId btrId in bt) {
    var btr = (BlockTableRecord)Tx.GetObject(btrId, OpenMode.ForRead);
    string where = btr.Name;
    if (btr.IsLayout) { var lay = (Layout)Tx.GetObject(btr.LayoutId, OpenMode.ForRead); where = "LAYOUT '" + lay.LayoutName + "'"; }
    foreach (ObjectId id in btr) {
        var o = Tx.GetObject(id, OpenMode.ForRead);
        string s = null;
        if (o is MText mt) s = mt.Contents;
        else if (o is DBText t) s = t.TextString;
        else if (o is BlockReference br && br.AttributeCollection != null) {
            foreach (ObjectId aid in br.AttributeCollection) {
                var ar = (AttributeReference)Tx.GetObject(aid, OpenMode.ForRead);
                if ((ar.TextString ?? "").ToUpperInvariant().Contains("VICINITY")) {
                    var d2 = (BlockTableRecord)Tx.GetObject(br.DynamicBlockTableRecord, OpenMode.ForRead);
                    Log($"[{where}] BLOCK '{d2.Name}' ATTR '{ar.Tag}' = \"{ar.TextString}\" @({ar.Position.X:F2},{ar.Position.Y:F2}) h={ar.Height:F2}");
                }
            }
            continue;
        }
        if (s == null || !s.ToUpperInvariant().Contains("VICINITY")) continue;
        var e = (Autodesk.AutoCAD.DatabaseServices.Entity)o;
        if (o is MText m2) Log($"[{where}] MText handle={e.Handle} layer={e.Layer} @({m2.Location.X:F3},{m2.Location.Y:F3}) h={m2.TextHeight:F3} attach={m2.Attachment} :: \"{m2.Contents}\"");
        else if (o is DBText t2) Log($"[{where}] DBText handle={e.Handle} layer={e.Layer} @({t2.Position.X:F3},{t2.Position.Y:F3}) h={t2.Height:F3} just={t2.Justify} :: \"{t2.TextString}\"");
    }
}
// also report existing raster images so we match convention / avoid duplicates
foreach (ObjectId btrId in bt) {
    var btr = (BlockTableRecord)Tx.GetObject(btrId, OpenMode.ForRead);
    string where = btr.Name;
    if (btr.IsLayout) { var lay = (Layout)Tx.GetObject(btr.LayoutId, OpenMode.ForRead); where = "LAYOUT '" + lay.LayoutName + "'"; }
    foreach (ObjectId id in btr) {
        var o = Tx.GetObject(id, OpenMode.ForRead);
        if (o is RasterImage ri) {
            var e = (Autodesk.AutoCAD.DatabaseServices.Entity)o;
            Log($"[{where}] RASTER handle={e.Handle} layer={e.Layer} name='{ri.ImageDefName}' size=({ri.Width:F2}x{ri.Height:F2})");
        }
    }
}
Log("Vicinity scan complete.");

Result

Status
error
Drawing file
C:\Users\sanja\OneDrive\_SurveyDisco\260702 - 358 St Johns Ave SW, Atlanta, GA 30315, USA\260702 - 358 St Johns Ave SW.dwg
Message
Compile error: (38,80): error CS1061: 'RasterImage' does not contain a definition for 'ImageDefName' and no accessible extension method 'ImageDefName' accepting a first argument of type 'RasterImage' could be found (are you missing a using directive or an assembly reference?)
Entities
Duration
328 ms
Civil 3D
25.0.0.0

Notes

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

No notes yet.