C3D-0256 · 260714 Huckaby: fix 17X11 viewport scale and bring the high sheet furniture down done
(A) The landscape viewport is half the portrait viewports height, so carrying the same view height gave 1inch=65.30feet. Sets view height to paperHeight*32.49 to restore 1inch=32.49feet. (B) The 105 entities rejected by the last pass all failed on Y, not X - the north arrow, SS_LEGEND and GA W.GRID sit at y 13.5-16.5 on the tall portrait sheet, off the top of an 11-inch landscape sheet. Copies them with dy=-5.6 so they land top-right, clear of the bottom-left title panel.
C# payload
// Two corrections to the 17X11 sheet:
//
// A. SCALE. The landscape viewport is 8.147 tall vs the portrait's 16.373, so carrying the same
// view height (532.00) halved the scale to 1"=65.30'. For 1"=32.49' the view height must be
// 8.147 * 32.49 = 264.70.
//
// B. THE MISSING FURNITURE. C3D-0254 shifted the notes +6.5 in X only and 105 entities were
// rejected - ALL of them for Y, not X: they sit at y 13.5..16.5 on the tall portrait sheet,
// which is off the top of an 11-inch landscape sheet. They are the north arrow (y~13.5-14.4),
// the legend block (y~13.4-16.6) and the GA W.GRID text. They need to come DOWN as well as
// across, into the band the portrait sheet used for its viewport.
const double CX = 1036448.40, CY = 465018.49;
LayoutManager.Current.CurrentLayout = "17X11";
Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("TILEMODE", 0);
var bt = (BlockTable)Tx.GetObject(Db.BlockTableId, OpenMode.ForRead);
BlockTableRecord src = null, dst = null;
foreach (ObjectId btrId in bt) {
var rec = (BlockTableRecord)Tx.GetObject(btrId, OpenMode.ForRead);
if (!rec.IsLayout) continue;
var lay = (Layout)Tx.GetObject(rec.LayoutId, OpenMode.ForRead);
if (lay.LayoutName == "11X17") src = rec;
if (lay.LayoutName == "17X11") dst = (BlockTableRecord)Tx.GetObject(btrId, OpenMode.ForWrite);
}
if (src == null || dst == null) { Log("layout missing"); return; }
// ---------- A. viewport scale
foreach (ObjectId id in dst) {
var vp = Tx.GetObject(id, OpenMode.ForRead) as Viewport;
if (vp == null || vp.Number == 1) continue;
var w = (Viewport)Tx.GetObject(id, OpenMode.ForWrite);
double want = w.Height * 32.49;
w.Locked = false;
w.ViewHeight = want;
w.ViewCenter = new Point2d(CX, CY);
w.Locked = true;
var back = (Viewport)Tx.GetObject(id, OpenMode.ForRead);
double sc = 0; try { sc = back.CustomScale; } catch { }
Log(string.Format("VP#{0}: paper {1:F3} tall, view h {2:F2} => 1\"={3:F2}' center ({4:F2},{5:F2}) (verified)",
back.Number, back.Height, back.ViewHeight, sc > 0 ? 1.0/sc : 0, back.ViewCenter.X, back.ViewCenter.Y));
}
// ---------- B. bring the high furniture down
// Anything on 11X17 above y=11.4 is off a landscape sheet. Drop it by 5.6 so the legend/north
// arrow band (13.4..16.6) lands at 7.8..11.0, top-right of the landscape sheet, clear of the
// title panel in the bottom left.
const double DX = 6.500, DY = -5.600;
var xform = Matrix3d.Displacement(new Vector3d(DX, DY, 0));
// what is already on the sheet, so nothing is duplicated
var have = new List<Extents3d>();
foreach (ObjectId id in dst) {
var ent = Tx.GetObject(id, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Entity;
if (ent == null || ent is Viewport || ent is BlockReference) continue;
try { have.Add(ent.GeometricExtents); } catch { }
}
int copied = 0, skipped = 0;
foreach (ObjectId id in src) {
var o = Tx.GetObject(id, OpenMode.ForRead);
if (o is Viewport) continue;
var srcBr = o as BlockReference;
if (srcBr != null && srcBr.Name.StartsWith("SS_BLOCK")) continue;
var ent = o as Autodesk.AutoCAD.DatabaseServices.Entity;
if (ent == null) continue;
double y1;
try { y1 = ent.GeometricExtents.MaxPoint.Y; } catch { continue; }
if (y1 <= 11.4) continue; // already handled by the previous pass
var clone = ent.Clone() as Autodesk.AutoCAD.DatabaseServices.Entity;
if (clone == null) continue;
clone.TransformBy(xform);
try {
var e = clone.GeometricExtents;
if (e.MinPoint.X < 0.1 || e.MaxPoint.X > 17.2 || e.MinPoint.Y < 0.1 || e.MaxPoint.Y > 11.1) {
clone.Dispose(); skipped++; continue;
}
} catch { }
dst.AppendEntity(clone);
Tx.AddNewlyCreatedDBObject(clone, true);
var cbr = clone as BlockReference;
if (cbr != null && srcBr != null) {
foreach (ObjectId aid in srcBr.AttributeCollection) {
var sar = Tx.GetObject(aid, OpenMode.ForRead) as AttributeReference;
if (sar == null) continue;
var nar = (AttributeReference)sar.Clone();
nar.TransformBy(xform);
cbr.AttributeCollection.AppendAttribute(nar);
Tx.AddNewlyCreatedDBObject(nar, true);
}
Log("copied block " + cbr.Name);
}
copied++;
}
Log(string.Format("high furniture copied down (dx={0:F2} dy={1:F2}): {2} still off-sheet: {3}", DX, DY, copied, skipped));
int n = 0;
foreach (ObjectId id in dst) n++;
Log("total entities on 17X11: " + n);
Ed.Regen();
Result
Log
VP#2: paper 8.147 tall, view h 264.70 => 1"=32.49' center (1036448.40,465018.49) (verified) copied block SS_LEGEND high furniture copied down (dx=6.50 dy=-5.60): 102 still off-sheet: 1 total entities on 17X11: 139
Notes
What worked, what didn't, job-specific gotchas — flagged notes feed the recipes.
No notes yet.