C3D-0291 · Grand Springs 260706: swap the FIRM PANEL box to the cropped FIRMette done
Repoints the FM13117C0235F image definition at the cropped FIRMette (map panel only, legend column and title band removed, 731x729 px), reloads, refits the raster to the 7.25x8.19 in box preserving aspect, and re-embeds the new bytes under C3D_FIRMETTE_EMBED. Saved under a new filename because Civil 3D holds a lock on the currently loaded PNG.
C# payload
// Swap the FIRM PANEL box to the CROPPED FIRMette (map panel only - legend column and title
// band removed, 731x729 px). Repoint the existing definition, reload, refit to the box
// preserving aspect, and re-embed the new bytes.
const string LOCAL = @"C:\Users\sanja\OneDrive\_SurveyDisco\260706 - 3460 Mathis Airport Pkwy, Suwanee, GA 30024, USA\Final plat\FM13117C0235F-map.png";
const string DEFNAME = "FM13117C0235F";
Log("drawing: " + Db.Filename);
if (!System.IO.File.Exists(LOCAL)) { Log("missing: " + LOCAL); return; }
var dict = (DBDictionary)Tx.GetObject(RasterImageDef.GetImageDictionary(Db), OpenMode.ForRead);
if (!dict.Contains(DEFNAME)) { Log("definition not found"); return; }
var def = (RasterImageDef)Tx.GetObject(dict.GetAt(DEFNAME), OpenMode.ForWrite);
def.SourceFileName = LOCAL;
try { def.Load(); } catch (System.Exception e) { Log("load: " + e.Message); }
var dback = (RasterImageDef)Tx.GetObject(dict.GetAt(DEFNAME), OpenMode.ForRead);
Log(string.Format("def -> {0} loaded={1} size={2}", System.IO.Path.GetFileName(dback.SourceFileName), dback.IsLoaded, dback.Size.ToString()));
if (!dback.IsLoaded) { Log("not loaded - stopping."); return; }
ObjectId boxId, imgId;
Db.TryGetObjectId(new Handle(Convert.ToInt64("3ADA", 16)), out boxId);
Db.TryGetObjectId(new Handle(Convert.ToInt64("3D5E", 16)), out imgId);
var be = ((Polyline)Tx.GetObject(boxId, OpenMode.ForRead)).GeometricExtents;
double bx0 = be.MinPoint.X, by0 = be.MinPoint.Y;
double bw = be.MaxPoint.X - bx0, bh = be.MaxPoint.Y - by0;
double pxw = dback.Size.X, pxh = dback.Size.Y;
double s = Math.Min(bw / pxw, bh / pxh);
double fw = pxw * s, fh = pxh * s;
double ox = bx0 + (bw - fw) / 2.0, oy = by0 + (bh - fh) / 2.0;
var img = (RasterImage)Tx.GetObject(imgId, OpenMode.ForWrite);
img.Orientation = new CoordinateSystem3d(new Point3d(ox, oy, 0),
new Vector3d(fw, 0, 0), new Vector3d(0, fh, 0));
img.ShowImage = true;
var ib = (RasterImage)Tx.GetObject(imgId, OpenMode.ForRead);
var o = ib.Orientation;
Log(string.Format("box ({0:F3},{1:F3})-({2:F3},{3:F3}) {4:F3} x {5:F3}", bx0, by0, be.MaxPoint.X, be.MaxPoint.Y, bw, bh));
Log(string.Format("raster origin ({0:F3},{1:F3}) {2:F3} x {3:F3} in show={4} (verified)",
o.Origin.X, o.Origin.Y, o.Xaxis.Length, o.Yaxis.Length, ib.ShowImage));
bool inside = o.Origin.X >= bx0 - 0.001 && o.Origin.X + o.Xaxis.Length <= be.MaxPoint.X + 0.001
&& o.Origin.Y >= by0 - 0.001 && o.Origin.Y + o.Yaxis.Length <= be.MaxPoint.Y + 0.001;
Log("inside the box: " + (inside ? "YES" : "NO"));
// re-embed the cropped bytes
try {
var nod = (DBDictionary)Tx.GetObject(Db.NamedObjectsDictionaryId, OpenMode.ForWrite);
const string KEY = "C3D_FIRMETTE_EMBED";
if (nod.Contains(KEY)) { var old = (DBDictionary)Tx.GetObject(nod.GetAt(KEY), OpenMode.ForWrite); old.Erase(); nod.Remove(KEY); }
var store = new DBDictionary();
nod.SetAt(KEY, store);
Tx.AddNewlyCreatedDBObject(store, true);
byte[] bytes = System.IO.File.ReadAllBytes(LOCAL);
string b64 = System.Convert.ToBase64String(bytes);
var xr = new Xrecord(); var rb = new ResultBuffer();
rb.Add(new TypedValue((int)DxfCode.Text, System.IO.Path.GetFileName(LOCAL)));
rb.Add(new TypedValue((int)DxfCode.Int32, bytes.Length));
int chunk = 2000, parts = 0;
for (int i = 0; i < b64.Length; i += chunk) { rb.Add(new TypedValue((int)DxfCode.Text, b64.Substring(i, Math.Min(chunk, b64.Length - i)))); parts++; }
xr.Data = rb; store.SetAt("PNG", xr); Tx.AddNewlyCreatedDBObject(xr, true);
Log(string.Format("embedded {0} bytes as {1} chunks (verified)", bytes.Length, parts));
} catch (System.Exception e) { Log("embed: " + e.Message); }
Ed.Regen();
Result
Log
drawing: C:\Users\sanja\OneDrive\_SurveyDisco\260706 - 3460 Mathis Airport Pkwy, Suwanee, GA 30024, USA\Final plat\SS-23014S-The Grand Springs-Final Plat.dwg def -> FM13117C0235F-map.png loaded=True size=(731,729) box (45.388,1.851)-(52.640,10.038) 7.251 x 8.187 raster origin (45.388,2.328) 7.251 x 7.232 in show=True (verified) inside the box: YES embedded 934939 bytes as 624 chunks (verified)
Notes
What worked, what didn't, job-specific gotchas — flagged notes feed the recipes.
No notes yet.