← Inbox

C3D-0417 · Repoint vicinity rasters to 260903 PNG + re-embed bytes [C3D-VICUPD] error

Vicinity rasters on 11X17/17X11 still point at the stale 260714 Huckaby PNG with Huckaby bytes embedded. Repoints every vicinity RasterImage def to the new 260903-vicinity.png (Google Static Maps, 812 Christmas Ave, zoom 15) and re-embeds those bytes in the C3D_VICINITY_EMBED xrecord. Rasters already placed - only source + embed change. Verifies the embed round-trips.

Script file
C3D-0417.cs
Target
812 Christmas Ave.dwg · paper space
Author
claude
Approved
yes · auto-auth
Timeout
180s

C# payload

// Repoint vicinity rasters to the NEW 260903 PNG and re-embed the bytes (was stale 260714 Huckaby).
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("new PNG missing on box: " + NEWPNG); return; }

var nod=(DBDictionary)Tx.GetObject(Db.NamedObjectsDictionaryId,OpenMode.ForWrite);
int repointed=0;
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;
        var def=(RasterImageDef)Tx.GetObject(ri.ImageDefId,OpenMode.ForWrite);
        string cur=def.SourceFileName ?? "";
        if(cur.ToLower().IndexOf("vicinity")<0) continue;
        if(!cur.Equals(NEWPNG,System.StringComparison.OrdinalIgnoreCase)){
            def.SourceFileName = NEWPNG;
            try{ def.Load(); }catch(System.Exception e){ Log("load: "+e.Message); }
            repointed++;
            Log("   raster ["+ri.Handle+"] def -> new png");
        }
    }
}
Log("repointed " + repointed + " raster(s)");

byte[] bytes=System.IO.File.ReadAllBytes(NEWPNG);
string b64=System.Convert.ToBase64String(bytes);
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 in " + chunks + " chunks");

{ var back=(Xrecord)Tx.GetObject(nod.GetAt(DICTKEY),OpenMode.ForRead); var sb=new System.Text.StringBuilder(); int idx=0; string fn=""; int dl=0;
  foreach(TypedValue tv in back.Data){ if(idx==0)fn=(string)tv.Value; else if(idx==1)dl=System.Convert.ToInt32(tv.Value); else if(idx>=3)sb.Append((string)tv.Value); idx++; }
  byte[] round=System.Convert.FromBase64String(sb.ToString());
  Log("VERIFY: fname=" + fn + " declared=" + dl + " decoded=" + round.Length + "  " + (round.Length==bytes.Length?"MATCH":"MISMATCH")); }
Ed.Regen();

Result

Status
error
Drawing file
C:\Users\sanja\OneDrive\_SurveyDisco\260903 - 812 Christmas Ave, Bethlehem, GA 30620, USA\812 Christmas Ave.dwg
Message
eNullObjectId
Entities
Duration
397 ms
Civil 3D
25.0.0.0

Log

drawing: C:\Users\sanja\OneDrive\_SurveyDisco\260903 - 812 Christmas Ave, Bethlehem, GA 30620, USA\812 Christmas Ave.dwg
   raster [215E7] def -> new png

Notes

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

No notes yet.