← Inbox

C3D-0009 · Vicinity map on 22X17 [VIC-260612] done

Places the Google Static Maps vicinity image (zoom 14, scale 2, red marker on 33.519202,-84.163861) 2.30in square above the VICINITY MAP label on the 22X17 sheet, layer BLOCK_CLOSURE, with a border. Follows the title-block-fill recipe geometry.

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

C# payload

// Vicinity map on the 22X17 sheet, per the title-block-fill recipe.
//
// Recipe cook (260702): Google Static Maps, zoom 14, scale 2, 640x640, red marker on the site,
// placed on layer BLOCK_CLOSURE at the label's x with a 0.075in gap above it, 2.30in square.
// Same geometry here. Label 'VICINITY MAP (NOT TO SCALE)' sits at (9.05,0.43)-(10.39,0.52) on
// 22X17, so the map is centred on the label's x = 9.72 and its bottom edge is 0.075in above
// the label top (0.52) -> bottom 0.595.
//
// Source PNG is on LOCAL TEMP, not OneDrive - a OneDrive path hydrating on demand is what made
// an earlier vicinity-map ticket blow past its timeout (cookbook 14).
// RasterImage is a LINK, not an embed; Ole2Frame cannot be built from a path in .NET (its
// LinkPath/Type are read-only), so embedding has to be done by hand if the link must go away.
// Idempotent: bails if a raster is already on the sheet. Host owns Tx; host regens after commit.
const string LAYOUT = "22X17", LAYER = "BLOCK_CLOSURE";
const string IMG = @"C:\Users\sanja\AppData\Local\Temp\vicinity_260612.png";
const string DEFNAME = "VICINITY_260612";
const double SIZE = 2.30;
const double CX = 9.72, BOTTOM = 0.595;

if (!System.IO.File.Exists(IMG)) { Log("NOT FOUND: " + IMG); return; }

var layDict = (DBDictionary)Tx.GetObject(Db.LayoutDictionaryId, OpenMode.ForRead);
if (!layDict.Contains(LAYOUT)) { Log("layout '" + LAYOUT + "' not found"); return; }
var layout = (Layout)Tx.GetObject(layDict.GetAt(LAYOUT), OpenMode.ForRead);
var ps = (BlockTableRecord)Tx.GetObject(layout.BlockTableRecordId, OpenMode.ForWrite);

foreach (ObjectId id in ps) {
    var r0 = Tx.GetObject(id, OpenMode.ForRead) as RasterImage;
    if (r0 != null) { Log("a raster is already on '" + LAYOUT + "' (h=" + r0.Handle + ") - nothing to do"); return; }
}

EnsureLayer(LAYER, 7);

var dictId = RasterImageDef.GetImageDictionary(Db);
if (dictId.IsNull) dictId = RasterImageDef.CreateImageDictionary(Db);
var dict = (DBDictionary)Tx.GetObject(dictId, OpenMode.ForWrite);

ObjectId defId;
if (dict.Contains(DEFNAME)) {
    defId = dict.GetAt(DEFNAME);
    var d0 = (RasterImageDef)Tx.GetObject(defId, OpenMode.ForWrite);
    d0.SourceFileName = IMG;
    if (!d0.IsLoaded) d0.Load();
    Log("reusing image def '" + DEFNAME + "'");
} else {
    var def = new RasterImageDef();
    def.SourceFileName = IMG;
    def.Load();
    defId = dict.SetAt(DEFNAME, def);
    Tx.AddNewlyCreatedDBObject(def, true);
    Log("created image def '" + DEFNAME + "'");
}

var ri = new RasterImage();
ri.ImageDefId = defId;
ri.Layer = LAYER;
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));

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 e2 = ri.GeometricExtents;
Log("vicinity map " + SIZE.ToString("F2") + "in square at (" +
    e2.MinPoint.X.ToString("F2") + "," + e2.MinPoint.Y.ToString("F2") + ")-(" +
    e2.MaxPoint.X.ToString("F2") + "," + e2.MaxPoint.Y.ToString("F2") + ")  handle=" + ri.Handle + " (verified)");
Log("label top was 0.52, map bottom " + e2.MinPoint.Y.ToString("F3") + " -> gap " +
    (e2.MinPoint.Y - 0.52).ToString("F3") + "in");

Result

Status
success
Drawing file
C:\Users\sanja\OneDrive\_SurveyDisco\260613 - 5030 E Lake Pkwy, Stockbridge, GA 30281, USA\260612 - CSTORE WATER ABS BOUNDARY.dwg
Message
Executed C3D-0009 (0 entities touched).
Entities
Duration
395 ms
Civil 3D
25.0.0.0

Log

created image def 'VICINITY_260612'
vicinity map 2.30in square at (8.57,0.59)-(10.87,2.89)  handle=2EC1F (verified)
label top was 0.52, map bottom 0.595 -> gap 0.075in

Notes

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

No notes yet.