C3D-PSRECENTER · Re-center 22x17 block after cleanup done
Recomputes extents of the cleaned-up SS_BLOCK_22X17 reference and re-centers it on the 22x17 sheet (centre 11, 8.5). Reads back and verifies.
C# payload
// Re-center the SS_BLOCK_22X17 reference on '22X17 C' after the block definition was cleaned up.
// Sheet is 22.00 x 17.00 in, centre (11, 8.5).
// Host owns Tx - no using/Commit here.
const string BLK = "SS_BLOCK_22X17", LAYOUT = "22X17 C";
var layDict = (DBDictionary)Tx.GetObject(Db.LayoutDictionaryId, OpenMode.ForRead);
var layout = (Layout)Tx.GetObject(layDict.GetAt(LAYOUT), OpenMode.ForRead);
var ps = (BlockTableRecord)Tx.GetObject(layout.BlockTableRecordId, OpenMode.ForWrite);
double sw = layout.PlotPaperSize.X / 25.4, sh = layout.PlotPaperSize.Y / 25.4;
int moved = 0;
foreach (ObjectId id in ps)
{
var b0 = Tx.GetObject(id, OpenMode.ForRead) as BlockReference;
if (b0 == null) continue;
var d0 = (BlockTableRecord)Tx.GetObject(b0.BlockTableRecord, OpenMode.ForRead);
if (d0.Name != BLK) continue;
var br = (BlockReference)Tx.GetObject(id, OpenMode.ForWrite);
Extents3d ext;
try { ext = br.GeometricExtents; } catch { Log(" extents unavailable"); continue; }
double bw = ext.MaxPoint.X - ext.MinPoint.X, bh = ext.MaxPoint.Y - ext.MinPoint.Y;
double cx = (ext.MinPoint.X + ext.MaxPoint.X)/2.0, cy = (ext.MinPoint.Y + ext.MaxPoint.Y)/2.0;
Log($" block now {bw:F2} x {bh:F2} in (was 25.18 x 16.48), centre ({cx:F3},{cy:F3})");
br.TransformBy(Matrix3d.Displacement(new Vector3d(sw/2.0 - cx, sh/2.0 - cy, 0)));
var e2 = br.GeometricExtents;
Log($" -> centre ({(e2.MinPoint.X+e2.MaxPoint.X)/2:F3},{(e2.MinPoint.Y+e2.MaxPoint.Y)/2:F3}) vs sheet ({sw/2:F2},{sh/2:F2}); extents ({e2.MinPoint.X:F2},{e2.MinPoint.Y:F2})-({e2.MaxPoint.X:F2},{e2.MaxPoint.Y:F2}) (verified)");
moved++;
}
Log($"Re-centered {moved} '{BLK}' reference(s) on the {sw:F0}x{sh:F0} sheet.");
Result
Log
block now 21.51 x 16.48 in (was 25.18 x 16.48), centre (9.164,8.500) -> centre (11.000,8.500) vs sheet (11.00,8.50); extents (0.25,0.26)-(21.75,16.74) (verified) Re-centered 1 'SS_BLOCK_22X17' reference(s) on the 22x17 sheet.
Notes
What worked, what didn't, job-specific gotchas — flagged notes feed the recipes.
No notes yet.