C3D-0419 · Repoint vicinity DEF to 260903 PNG + re-embed (guard null-def orphans) [C3D-VICUPD2] done
Retry of C3D-0417 (eNullObjectId from two orphan rasters on layer 0 with null ImageDefId). Skips null-def rasters, repoints the shared vicinity RasterImageDef to 260903-vicinity.png, reloads it, and re-embeds the bytes in the C3D_VICINITY_EMBED xrecord. Verifies embed round-trip.
C# payload
// Repoint the vicinity image DEF (shared by both rasters) to the new 260903 PNG, re-embed bytes.
// Guard: skip rasters with a null ImageDefId (two orphans on layer 0 caused eNullObjectId before).
const string NEWPNG=@"C:\Users\sanja\OneDrive\_SurveyDisco\260903 - 812 Christmas Ave, Bethlehem, GA 30620, USA\260903-vicinity.png"; const string DICTKEY="C3D_VICINITY_EMBED";
Log("drawing: " + Db.Filename);
if(!System.IO.File.Exists(NEWPNG)){ Log("PNG missing: "+NEWPNG); return; }
// collect the distinct vicinity defs via valid rasters
var defs=new HashSet<ObjectId>();
var bt=(BlockTable)Tx.GetObject(Db.BlockTableId,OpenMode.ForRead);
foreach (ObjectId bid in bt){ var b=(BlockTableRecord)Tx.GetObject(bid,OpenMode.ForRead); foreach (ObjectId id in b){
var ri=Tx.GetObject(id,OpenMode.ForRead) as RasterImage; if(ri==null) continue;
if(ri.ImageDefId.IsNull){ Log(" skip orphan raster ["+ri.Handle+"] (null def)"); continue; }
var def=(RasterImageDef)Tx.GetObject(ri.ImageDefId,OpenMode.ForRead);
string cur=def.SourceFileName ?? ""; if(cur.ToLower().IndexOf("vicinity")<0) continue;
defs.Add(ri.ImageDefId);
}}
int repointed=0;
foreach(var defId in defs){ var def=(RasterImageDef)Tx.GetObject(defId,OpenMode.ForWrite);
if(!def.SourceFileName.Equals(NEWPNG,System.StringComparison.OrdinalIgnoreCase)){
def.SourceFileName=NEWPNG; try{ def.Load(); }catch(System.Exception e){ Log("load: "+e.Message); }
repointed++; Log(" def ["+def.Handle+"] -> new png, loaded="+def.IsLoaded);
}
}
Log("repointed " + repointed + " def(s)");
byte[] bytes=System.IO.File.ReadAllBytes(NEWPNG); string b64=System.Convert.ToBase64String(bytes);
var nod=(DBDictionary)Tx.GetObject(Db.NamedObjectsDictionaryId,OpenMode.ForWrite);
if(nod.Contains(DICTKEY)) nod.Remove(DICTKEY);
var xrec=new Xrecord(); var rb=new ResultBuffer(); string fname=System.IO.Path.GetFileName(NEWPNG);
int CHUNK=2000; int chunks=(b64.Length+CHUNK-1)/CHUNK;
rb.Add(new TypedValue((int)DxfCode.Text,fname)); rb.Add(new TypedValue((int)DxfCode.Int32,bytes.Length)); rb.Add(new TypedValue((int)DxfCode.Int32,chunks));
for(int i=0;i<chunks;i++){ int len=System.Math.Min(CHUNK,b64.Length-i*CHUNK); rb.Add(new TypedValue((int)DxfCode.Text,b64.Substring(i*CHUNK,len))); }
xrec.Data=rb; nod.SetAt(DICTKEY,xrec); Tx.AddNewlyCreatedDBObject(xrec,true);
Log("re-embedded " + fname + ": " + bytes.Length + " bytes, " + chunks + " chunks");
{ var back=(Xrecord)Tx.GetObject(nod.GetAt(DICTKEY),OpenMode.ForRead); var sb=new System.Text.StringBuilder(); int idx=0; int dl=0;
foreach(TypedValue tv in back.Data){ if(idx==1)dl=System.Convert.ToInt32(tv.Value); else if(idx>=3)sb.Append((string)tv.Value); idx++; }
byte[] r=System.Convert.FromBase64String(sb.ToString()); Log("VERIFY embed: declared="+dl+" decoded="+r.Length+" "+(r.Length==bytes.Length?"MATCH":"MISMATCH")); }
Ed.Regen();
Result
Log
drawing: C:\Users\sanja\OneDrive\_SurveyDisco\260903 - 812 Christmas Ave, Bethlehem, GA 30620, USA\812 Christmas Ave.dwg skip orphan raster [1DAC] (null def) skip orphan raster [1240A] (null def) def [215E6] -> new png, loaded=True repointed 1 def(s) re-embedded 260903-vicinity.png: 103374 bytes, 69 chunks VERIFY embed: declared=103374 decoded=103374 MATCH
Notes
What worked, what didn't, job-specific gotchas — flagged notes feed the recipes.
No notes yet.