C3D-0207 · Vicinity map at 33.51902614, -84.16534004 done
Re-fetches the vicinity map centred on the coordinate the user supplied and repoints the VICINITY image definition at it. Saved under a new filename because the previous PNG is locked open by the running Civil 3D session. The frame keeps its position and size; the image lives in the job folder, not Windows temp.
C# payload
// Point the vicinity map at the coordinate the user gave: 33.51902614569263, -84.16534004126642.
//
// Written to a NEW filename because the previous PNG is locked open by this Civil 3D session -
// overwriting it in place fails with a permission error while the drawing holds it.
//
// Only the SourceFileName of the VICINITY definition changes; the frame on the sheet keeps its
// position and size. The image lives in the job folder, never the Windows temp folder - a temp
// path is what left this frame blank in the first place.
const string NEWPATH = @"C:\Users\sanja\OneDrive\_SurveyDisco\260613 - 5030 E Lake Pkwy, Stockbridge, GA 30281, USA\260612-vicinity-map-2.png";
if (!System.IO.File.Exists(NEWPATH)) { Log("ABORT: image not found: " + NEWPATH); return; }
Log("drawing: " + Db.Filename);
Log("new source: " + NEWPATH + " (" + new System.IO.FileInfo(NEWPATH).Length + " bytes)");
var dictId = RasterImageDef.GetImageDictionary(Db);
if (dictId.IsNull) { Log("ABORT: no image dictionary"); return; }
var dict = (DBDictionary)Tx.GetObject(dictId, OpenMode.ForRead);
int n = 0;
foreach (DBDictionaryEntry de in dict) {
var def0 = Tx.GetObject(de.Value, OpenMode.ForRead) as RasterImageDef;
if (def0 == null) continue;
if (!(def0.SourceFileName ?? "").ToUpper().Contains("VICINITY")) continue;
Log("");
Log("definition \"" + de.Key + "\"");
Log(" was: " + def0.SourceFileName + " loaded=" + def0.IsLoaded);
var def = (RasterImageDef)Tx.GetObject(de.Value, OpenMode.ForWrite);
def.SourceFileName = NEWPATH;
try { def.Load(); } catch (System.Exception ex) { Log(" load: " + ex.Message); }
Log(" now: " + def.SourceFileName + " loaded=" + def.IsLoaded);
n++;
}
Log("");
Log("definitions repointed: " + n);
Log("");
Log("=== VERIFY ===");
var bt = (BlockTable)Tx.GetObject(Db.BlockTableId, OpenMode.ForRead);
int ok = 0, bad = 0;
foreach (ObjectId btrId in bt) {
var btr = (BlockTableRecord)Tx.GetObject(btrId, OpenMode.ForRead);
foreach (ObjectId id in btr) {
var ri = Tx.GetObject(id, OpenMode.ForRead) as RasterImage;
if (ri == null || ri.IsErased) continue;
string p = "(none)"; bool exists = false, loaded = false;
try {
var d2 = (RasterImageDef)Tx.GetObject(ri.ImageDefId, OpenMode.ForRead);
p = d2.SourceFileName; loaded = d2.IsLoaded; exists = System.IO.File.Exists(p);
} catch { continue; }
if (exists) ok++; else bad++;
Log(String.Format(" [{0}] exists={1,-5} loaded={2,-5} {3}", ri.Handle, exists, loaded, p));
}
}
Log(" rasters resolving to a real file: " + ok + " missing: " + bad + " (verified)");
Ed.Regen();
Result
Log
drawing: C:\Users\sanja\OneDrive\_SurveyDisco\260613 - 5030 E Lake Pkwy, Stockbridge, GA 30281, USA\260612-Springdale Sanitary Sewer Extension As-Built 60.dwg new source: C:\Users\sanja\OneDrive\_SurveyDisco\260613 - 5030 E Lake Pkwy, Stockbridge, GA 30281, USA\260612-vicinity-map-2.png (58716 bytes) definition "VICINITY_260612" was: C:\Users\sanja\OneDrive\_SurveyDisco\260613 - 5030 E Lake Pkwy, Stockbridge, GA 30281, USA\260612-vicinity-map.png loaded=True now: C:\Users\sanja\OneDrive\_SurveyDisco\260613 - 5030 E Lake Pkwy, Stockbridge, GA 30281, USA\260612-vicinity-map-2.png loaded=True definitions repointed: 1 === VERIFY === [2EC1F] exists=True loaded=True C:\Users\sanja\OneDrive\_SurveyDisco\260613 - 5030 E Lake Pkwy, Stockbridge, GA 30281, USA\260612-vicinity-map-2.png [2823E] exists=True loaded=True C:\Users\sanja\OneDrive\_SurveyDisco\260613 - 5030 E Lake Pkwy, Stockbridge, GA 30281, USA\PDF Images\As Built - DEV3896 East Lake Pkwy C-Store - Water & Sewer087bf8df.png rasters resolving to a real file: 2 missing: 0 (verified)
Notes
What worked, what didn't, job-specific gotchas — flagged notes feed the recipes.
No notes yet.