C3D-BORDERROT · Rotate 11X17 border portrait->landscape, fit to paper done
Rotate SS_BLOCK_11X17 90 CW about insertion, translate lower-left to layout limits. Computed transform, read-back verify. Only the border touched.
C# payload
// Rotate the portrait border SS_BLOCK_11X17 to landscape and fit it to the layout's landscape limits.
// Approach (computed, not hardcoded):
// 1. read the border's current extents + the layout limits
// 2. rotate the block 90° CW about its insertion point (portrait 10.65x16.48 -> landscape 16.48x10.65)
// 3. translate so the rotated border's lower-left aligns to the layout limits' lower-left
// 4. read back and log the new extents to confirm it sits inside the paper
// Only the border block is transformed; nothing else touched. Verify-after built in.
using System;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
var db = Db;
using (var tr = db.TransactionManager.StartTransaction())
{
var ld = (DBDictionary)tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead);
Layout lay = null;
foreach (DBDictionaryEntry e in ld)
{
var l = (Layout)tr.GetObject(e.Value, OpenMode.ForRead);
if (string.Equals(l.LayoutName, "11X17", StringComparison.OrdinalIgnoreCase)) { lay = l; break; }
}
if (lay == null) { Log("11X17 not found"); tr.Commit(); return; }
var limMin = lay.Limits.MinPoint; // landscape plottable lower-left
var limMax = lay.Limits.MaxPoint;
Log($"limits: ({limMin.X:0.00},{limMin.Y:0.00}) -> ({limMax.X:0.00},{limMax.Y:0.00}) size {limMax.X-limMin.X:0.00}x{limMax.Y-limMin.Y:0.00}");
var btr = (BlockTableRecord)tr.GetObject(lay.BlockTableRecordId, OpenMode.ForWrite);
BlockReference border = null;
foreach (ObjectId id in btr)
{
var br = tr.GetObject(id, OpenMode.ForRead) as BlockReference;
if (br == null) continue;
var bdef = (BlockTableRecord)tr.GetObject(br.BlockTableRecord, OpenMode.ForRead);
if (bdef.Name.Contains("11X17")) { border = (BlockReference)tr.GetObject(id, OpenMode.ForWrite); break; }
}
if (border == null) { Log("border block not found"); tr.Commit(); return; }
var before = border.GeometricExtents;
Log($"BEFORE: extents ({before.MinPoint.X:0.00},{before.MinPoint.Y:0.00})->({before.MaxPoint.X:0.00},{before.MaxPoint.Y:0.00}) rot={border.Rotation*180/Math.PI:0.0}");
// 1) rotate 90° CW about insertion
var ins = border.Position;
border.TransformBy(Matrix3d.Rotation(-Math.PI/2.0, Vector3d.ZAxis, ins));
// 2) recompute extents after rotation, then translate lower-left -> limits lower-left
var rot = border.GeometricExtents;
double dx = limMin.X - rot.MinPoint.X;
double dy = limMin.Y - rot.MinPoint.Y;
border.TransformBy(Matrix3d.Displacement(new Vector3d(dx, dy, 0)));
var after = border.GeometricExtents;
Log($"rotated 90 CW, translated ({dx:0.00},{dy:0.00})");
Log($"AFTER: extents ({after.MinPoint.X:0.00},{after.MinPoint.Y:0.00})->({after.MaxPoint.X:0.00},{after.MaxPoint.Y:0.00}) rot={border.Rotation*180/Math.PI:0.0} size {after.MaxPoint.X-after.MinPoint.X:0.00}x{after.MaxPoint.Y-after.MinPoint.Y:0.00}");
// 3) sanity: does it fit inside the limits (with small tolerance)?
bool fits = after.MinPoint.X >= limMin.X-0.5 && after.MinPoint.Y >= limMin.Y-0.5
&& after.MaxPoint.X <= limMax.X+0.5 && after.MaxPoint.Y <= limMax.Y+0.5;
Log(fits ? "FITS inside layout limits." : "WARNING: border extends beyond limits — may need scaling.");
tr.Commit();
}
Log("DONE. Border rotated to landscape + aligned to paper lower-left.");
Result
Log
limits: (-0.67,-0.20) -> (16.33,10.80) size 17.00x11.00 BEFORE: extents (5.40,0.10)->(16.05,16.57) rot=0.0 rotated 90 CW, translated (-16.72,-0.29) AFTER: extents (-0.67,-0.20)->(15.81,10.45) rot=270.0 size 16.48x10.65 FITS inside layout limits. DONE. Border rotated to landscape + aligned to paper lower-left.
Notes
What worked, what didn't, job-specific gotchas — flagged notes feed the recipes.
No notes yet.