C3D-0168 · Reload block + inline flood sentence values [RELOAD-BLOCK-2] done
Replaces the SS_BLOCK_11X17 definition from the block file and refills every attribute for job 260714, with the connecting words baked into the flood values so panel, date and zone read as one continuous sentence.
C# payload
// Replace this drawing's stale SS_BLOCK_11X17 definition with the updated one from the block
// file (which now carries the flood note + FIRM_PANEL / FIRM_DATE / FLOOD_ZONE attributes), then
// refill every attribute for job 260714.
//
// Method: read the block DEFINITION out of the source drawing with a side database and
// WblockCloneObjects with DuplicateRecordCloning.Replace - that redefines the block in place, so
// the existing insert keeps its position and simply picks up the new definition. Safer than
// erase + purge + re-insert, which loses the placement.
//
// Attribute values come from GET /api/project-by-id?job_number=260714 plus the FEMA fields:
// firmPanel 13113C0155E | firmPanelDate 09/26/2008 | floodZone X
// The connecting words are baked INTO the values (", EFFECTIVE", ", AND LIES IN ZONE", ".") so the
// three attributes read as one continuous sentence with no extra static text between them.
//
// Only SS_BLOCK_11X17 is touched.
const string BLOCK = "SS_BLOCK_11X17";
const string SRC = @"C:\Users\sanja\OneDrive\_SurveyDisco\SS_BLOCK_11X17.dwg";
Log("drawing: " + Db.Filename);
if (!System.IO.File.Exists(SRC)) { Log("ABORT: source block file not found: " + SRC); return; }
// --- 1. pull the updated definition in, replacing the local one ---
using (var side = new Database(false, true))
{
side.ReadDwgFile(SRC, FileOpenMode.OpenForReadAndAllShare, false, null);
side.CloseInput(true);
var srcBt = (BlockTable)side.TransactionManager.StartTransaction().GetObject(side.BlockTableId, OpenMode.ForRead);
// (the side transaction is disposed with the side database)
var ids = new ObjectIdCollection();
if (!srcBt.Has(BLOCK)) { Log("ABORT: " + BLOCK + " not in the source file"); return; }
ids.Add(srcBt[BLOCK]);
var map = new IdMapping();
Db.WblockCloneObjects(ids, Db.BlockTableId, map, DuplicateRecordCloning.Replace, false);
Log("definition replaced from " + SRC);
}
// --- 2. sync every insert to the new attribute set, preserving values where the tag survives ---
var bt = (BlockTable)Tx.GetObject(Db.BlockTableId, OpenMode.ForRead);
var defBtr = (BlockTableRecord)Tx.GetObject(bt[BLOCK], OpenMode.ForRead);
// the definition's attribute defs, in order
var defs = new List<AttributeDefinition>();
foreach (ObjectId id in defBtr) {
var ad = Tx.GetObject(id, OpenMode.ForRead) as AttributeDefinition;
if (ad != null && !ad.Constant) defs.Add(ad);
}
Log("definition now has " + defs.Count + " attribute definitions");
var want = new Dictionary<string,string>();
want["JOB_NO"] = "JOB NO.: 260714";
want["SITE_ADDRESS"] = "285 Huckaby Rd, Brooks, GA 30205, USA";
want["COUNTY"] = "COUNTY: Fayette";
want["LAND_LOT"] = "LAND LOT: 124";
want["DISTRICT"] = "DISTRICT: 4th";
want["DATE"] = "DATE: 08/13/26";
want["SURVEY_TYPE"] = "Boundary Survey";
want["PREP_FOR"] = "JOY EWING";
want["REF_DB_PG"] = "REF DB 5857 Page 692";
want["SUBDIVISION_NAME_LOT"] = "";
want["FIRM_PANEL"] = "13113C0155E, EFFECTIVE";
want["FIRM_DATE"] = "SEPTEMBER 26, 2008, AND LIES IN ZONE";
want["FLOOD_ZONE"] = "X.";
int inserts = 0;
foreach (ObjectId btrId in bt) {
var btr = (BlockTableRecord)Tx.GetObject(btrId, OpenMode.ForRead);
foreach (ObjectId id in btr) {
var br0 = Tx.GetObject(id, OpenMode.ForRead) as BlockReference;
if (br0 == null || br0.Name != BLOCK) continue;
inserts++;
var br = (BlockReference)Tx.GetObject(id, OpenMode.ForWrite);
Log("");
Log("insert [" + br.Handle + "] in " + btr.Name + " at "
+ br.Position.X.ToString("F4") + "," + br.Position.Y.ToString("F4"));
// keep whatever values the old attributes had, keyed by tag
var had = new Dictionary<string,string>();
foreach (ObjectId aid in br.AttributeCollection) {
var at = Tx.GetObject(aid, OpenMode.ForRead) as AttributeReference;
if (at != null) had[at.Tag] = at.TextString;
}
// rebuild the attribute collection from the NEW definition
foreach (ObjectId aid in br.AttributeCollection) {
var at = (AttributeReference)Tx.GetObject(aid, OpenMode.ForWrite);
at.Erase();
}
foreach (var ad in defs) {
var ar = new AttributeReference();
ar.SetAttributeFromBlock(ad, br.BlockTransform);
string v = want.ContainsKey(ad.Tag) ? want[ad.Tag]
: (had.ContainsKey(ad.Tag) ? had[ad.Tag] : ad.TextString);
ar.TextString = v;
br.AttributeCollection.AppendAttribute(ar);
Tx.AddNewlyCreatedDBObject(ar, true);
Log(String.Format(" {0,-22} = \"{1}\"", ad.Tag, v));
}
}
}
Log("");
Log("inserts updated: " + inserts + " (verified)");
Ed.Regen();
Result
Log
drawing: C:\Users\sanja\OneDrive\_SurveyDisco\260714 - 285 Huckaby Rd, Brooks, GA 30205, USA\260714 - 285 Huckaby Rd.dwg definition replaced from C:\Users\sanja\OneDrive\_SurveyDisco\SS_BLOCK_11X17.dwg definition now has 13 attribute definitions inserts updated: 0 (verified)
Notes
What worked, what didn't, job-specific gotchas — flagged notes feed the recipes.
No notes yet.