C3D-0146 · READ-ONLY: vicinity map label position and enclosing block [VIC-POS] error
Reports the VICINITY MAP label in paper space with its extents and layer, any polyline, line or block reference enclosing it, and an existing OLE frame for reference, so the vicinity image can be placed over the label inside the block boundary. No changes.
C# payload
// READ-ONLY. Where does the vicinity map go? Report the VICINITY MAP label in *Paper_Space and the
// geometry of the block/border it sits inside, so an image can be placed over it within the block
// boundary. Also dump an existing Ole2Frame for reference. Nothing is modified.
var bt = (BlockTable)Tx.GetObject(Db.BlockTableId, OpenMode.ForRead);
Log("drawing: " + Db.Filename);
var ps = (BlockTableRecord)Tx.GetObject(bt[BlockTableRecord.PaperSpace], OpenMode.ForRead);
Log("=== the VICINITY MAP label in *Paper_Space ===");
Extents3d? lblExt = null;
foreach (ObjectId id in ps) {
Autodesk.AutoCAD.DatabaseServices.DBObject o;
try { o = Tx.GetObject(id, OpenMode.ForRead); } catch { continue; }
string s = null;
var mt = o as MText; if (mt != null) s = mt.Contents;
var dt = o as DBText; if (dt != null) s = dt.TextString;
if (s == null || s.ToUpper().IndexOf("VICINITY") < 0) continue;
var ent = (Autodesk.AutoCAD.DatabaseServices.Entity)o;
var e = ent.GeometricExtents;
lblExt = e;
Log(String.Format(" [{0}] {1} layer={2}", o.Handle, o.GetType().Name, ent.Layer));
Log(String.Format(" text \"{0}\"", s));
Log(String.Format(" extents {0:F3},{1:F3} -> {2:F3},{3:F3}", e.MinPoint.X, e.MinPoint.Y, e.MaxPoint.X, e.MaxPoint.Y));
if (mt != null) Log(String.Format(" location {0:F3},{1:F3} height {2:F3}", mt.Location.X, mt.Location.Y, mt.TextHeight));
}
// what encloses it? report nearby closed polylines / lines in paper space
if (lblExt.HasValue) {
var L = lblExt.Value;
double cx = (L.MinPoint.X + L.MaxPoint.X)/2, cy = (L.MinPoint.Y + L.MaxPoint.Y)/2;
Log("");
Log(String.Format("=== geometry near the label (centre {0:F2},{1:F2}) ===", cx, cy));
foreach (ObjectId id in ps) {
Autodesk.AutoCAD.DatabaseServices.DBObject o;
try { o = Tx.GetObject(id, OpenMode.ForRead); } catch { continue; }
var ent = o as Autodesk.AutoCAD.DatabaseServices.Entity;
if (ent == null) continue;
if (!(o is Polyline || o is Line || o is BlockReference)) continue;
Extents3d e;
try { e = ent.GeometricExtents; } catch { continue; }
double ecx=(e.MinPoint.X+e.MaxPoint.X)/2, ecy=(e.MinPoint.Y+e.MaxPoint.Y)/2;
if (Math.Abs(ecx-cx) > 12 || Math.Abs(ecy-cy) > 12) continue;
Log(String.Format(" [{0}] {1,-14} layer={2,-18} {3:F3},{4:F3} -> {5:F3},{6:F3} ({7:F2} x {8:F2})",
o.Handle, o.GetType().Name, ent.Layer, e.MinPoint.X, e.MinPoint.Y, e.MaxPoint.X, e.MaxPoint.Y,
e.MaxPoint.X-e.MinPoint.X, e.MaxPoint.Y-e.MinPoint.Y));
}
}
Log("");
Log("=== an existing Ole2Frame for reference ===");
foreach (ObjectId btrId in bt) {
var btr = (BlockTableRecord)Tx.GetObject(btrId, OpenMode.ForRead);
foreach (ObjectId id in btr) {
var ol = Tx.GetObject(id, OpenMode.ForRead) as Ole2Frame;
if (ol == null) continue;
var e = ol.GeometricExtents;
Log(String.Format(" [{0}] in {1} layer={2} {3:F2} x {4:F2} type={5}",
ol.Handle, btr.Name, ol.Layer, e.MaxPoint.X-e.MinPoint.X, e.MaxPoint.Y-e.MinPoint.Y, ol.OleType));
try { Log(" UserName " + ol.UserName); } catch { }
}
}
Result
Notes
What worked, what didn't, job-specific gotchas — flagged notes feed the recipes.
No notes yet.