← Inbox

C3D-260619-VICMAP · Vicinity map on 22X17 C done

Places the Google Static Maps vicinity image (roadmap z14, marker on site) 2.6in square above the VICINITY MAP label, with a border. Source is a local temp PNG, not OneDrive.

Script file
C3D-260619-VICMAP.cs
Target
260619 · paper space
Author
claude
Approved
yes · auto-auth
Timeout
180s

C# payload

// Vicinity map for 260619, placed above the "VICINITY MAP (NOT TO SCALE)" label on 22X17 C.
// Google Static Maps roadmap z14 with a marker on the site, from a LOCAL temp PNG (not OneDrive -
// a OneDrive path hydrating on demand is what made the earlier attempt blow past its timeout).
// RasterImage is a LINK, not an embed: Ole2Frame's LinkPath/Type/Location are all read-only in
// the .NET API (verified by reflecting AcDbMgd), so OLE embedding is not reachable from a script.
// The user can OLE-embed by hand later if the link needs to go away.
// Host owns Tx; host regens + UpdateScreen after commit.
const string LAYOUT = "22X17 C", LAYER = "BLOCK_CLOSURE";
const string IMG = @"C:\Users\sanja\AppData\Local\Temp\vicinity_260619.png";
const string DEFNAME = "VICINITY_260619";
const double SIZE = 2.60;
const double CX = 9.16, BOTTOM = 0.68;

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);

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;          // repoint at the local copy
    if (!d0.IsLoaded) d0.Load();
    Log("reusing image def, repointed to local temp");
}
else
{
    var def = new RasterImageDef();
    def.SourceFileName = IMG;
    def.Load();
    defId = dict.SetAt(DEFNAME, def);
    Tx.AddNewlyCreatedDBObject(def, true);
    Log("created image def '" + DEFNAME + "'");
}

foreach (ObjectId id in ps)
{
    var ri0 = Tx.GetObject(id, OpenMode.ForRead) as RasterImage;
    if (ri0 != null && ri0.ImageDefId == defId) { Log("already placed (h=" + ri0.Handle + ") - nothing to do"); return; }
}

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 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

Status
success
Drawing file
C:\Users\sanja\OneDrive\_SurveyDisco\260619 - 3625 Stonewall Tell Rd, Atlanta, GA 30349, USA\260619 - 3625 Stonewall Tell Rd ROTATE.dwg
Message
Executed C3D-260619-VICMAP (0 entities touched).
Entities
Duration
1780 ms
Civil 3D
25.0.0.0

Log

created image def 'VICINITY_260619'
Placed vicinity map 2.60in square at (7.86,0.68)-(10.46,3.28) handle=224FD (verified)

Notes

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

No notes yet.