C3D-VICMAP · Place vicinity map image running
Attaches the Google Static Maps vicinity image (roadmap, zoom 14, marker on site) above the VICINITY MAP label on 22X17 C, 2.6in square with a border.
C# payload
// Attach the vicinity map raster above the "VICINITY MAP (NOT TO SCALE)" label on 22X17 C.
// Google Static Maps roadmap, zoom 14, centred on the site (33.6562379,-84.5937887) with a
// marker. Label sits at (8.48,0.51)-(9.83,0.60), so the image is centred on x=9.16 and its
// bottom edge placed just above the label. Square image -> square placement.
// Also draws a border around it. Host owns Tx; host regens after commit.
const string LAYOUT = "22X17 C", LAYER = "BLOCK_CLOSURE";
const string IMG = @"C:\Users\sanja\OneDrive\_SurveyDisco\260619 - 3625 Stonewall Tell Rd, Atlanta, GA 30349, USA\vicinity_260619.png";
const double SIZE = 2.60; // inches on the sheet, square
const double CX = 9.16, BOTTOM = 0.68; // centred over the label, just above it
if (!System.IO.File.Exists(IMG)) { Log("NOT FOUND: " + IMG); return; }
var layDict = (DBDictionary)Tx.GetObject(Db.LayoutDictionaryId, OpenMode.ForRead);
var layout = (Layout)Tx.GetObject(layDict.GetAt(LAYOUT), OpenMode.ForRead);
var ps = (BlockTableRecord)Tx.GetObject(layout.BlockTableRecordId, OpenMode.ForWrite);
// image dictionary + definition
var dictId = RasterImageDef.GetImageDictionary(Db);
if (dictId.IsNull) dictId = RasterImageDef.CreateImageDictionary(Db);
var dict = (DBDictionary)Tx.GetObject(dictId, OpenMode.ForWrite);
const string DEFNAME = "VICINITY_260619";
ObjectId defId;
if (dict.Contains(DEFNAME)) { defId = dict.GetAt(DEFNAME); Log("reusing image def"); }
else
{
var def = new RasterImageDef();
def.SourceFileName = IMG;
def.Load();
defId = dict.SetAt(DEFNAME, def);
Tx.AddNewlyCreatedDBObject(def, true);
Log("created image def '" + DEFNAME + "'");
}
// already placed?
foreach (ObjectId id in ps)
{
var ri0 = Tx.GetObject(id, OpenMode.ForRead) as RasterImage;
if (ri0 != null && ri0.ImageDefId == defId) { Log("vicinity map already placed (h=" + ri0.Handle + ")"); return; }
}
var ri = new RasterImage();
ri.ImageDefId = defId;
ri.Layer = LAYER;
// lower-left corner + u/v vectors sized in sheet inches
var origin = new Point3d(CX - SIZE/2.0, BOTTOM, 0.0);
ri.Orientation = new CoordinateSystem3d(origin, new Vector3d(SIZE, 0, 0), new Vector3d(0, SIZE, 0));
ri.ShowImage = true;
ps.AppendEntity(ri);
Tx.AddNewlyCreatedDBObject(ri, true);
ri.AssociateRasterDef((RasterImageDef)Tx.GetObject(defId, OpenMode.ForWrite));
// border
var pl = new Polyline();
pl.AddVertexAt(0, new Point2d(origin.X, origin.Y), 0, 0, 0);
pl.AddVertexAt(1, new Point2d(origin.X + SIZE, origin.Y), 0, 0, 0);
pl.AddVertexAt(2, new Point2d(origin.X + SIZE, origin.Y + SIZE), 0, 0, 0);
pl.AddVertexAt(3, new Point2d(origin.X, origin.Y + SIZE), 0, 0, 0);
pl.Closed = true;
pl.Layer = LAYER;
ps.AppendEntity(pl);
Tx.AddNewlyCreatedDBObject(pl, true);
var e = ri.GeometricExtents;
Log("Placed vicinity map " + SIZE.ToString("F2") + "in square at (" +
e.MinPoint.X.ToString("F2") + "," + e.MinPoint.Y.ToString("F2") + ")-(" +
e.MaxPoint.X.ToString("F2") + "," + e.MaxPoint.Y.ToString("F2") + ") handle=" + ri.Handle + " (verified)");
Result
Log
created image def 'VICINITY_260619' Placed vicinity map 2.60in square at (7.86,0.68)-(10.46,3.28) handle=224BC (verified)
Notes
What worked, what didn't, job-specific gotchas — flagged notes feed the recipes.
No notes yet.