C3D-0254 · 260714 Huckaby: fix the 17X11 sheet - viewport view, missing notes, media, stray viewport, insert position done
Repairs the five defects the audit found. (1) The viewport was showing 1inch=9876feet at coordinates far off site because ViewCenter/CustomScale were assigned to a LOCKED viewport - now unlocked, ViewHeight set first then center, then relocked. (2) Copies the sheet furniture from 11X17 (property-lines note, UPC dig block, field closure, GA W.GRID, vicinity label, SS_LEGEND) shifted +6.5 in X for the landscape aspect, rejecting anything that lands off-sheet. (3) Prefers a true 17x11 media over the generic ANSI_full_bleed_B forced landscape by rotation. (4) Erases the inert viewport left inside the block definition. (5) Reseats the block insert so it stops overhanging the sheet top.
C# payload
// Repair the 17X11 sheet. The audit (C3D-0253) found five defects:
// 1. VP#2 view is (2089122,1226671) h=80462 -> 1"=9876'. Nowhere near the site. Setting
// ViewCenter then CustomScale on a LOCKED viewport re-derives the view, so it must be
// unlocked, set height+center, THEN locked.
// 2. The sheet has 3 entities; 11X17 has 141. Every sheet note and the legend block are missing.
// 3. Media is the generic "ANSI_full_bleed_B" (11x17 portrait) forced landscape by a 90 deg
// plot rotation. Prefer a true 17x11 media if one is registered.
// 4. A stray viewport is still inside the SS_BLOCK_17X11 definition (inert but wrong).
// 5. The block insert runs to y=11.290 on an 11.000 sheet - drop it to sit inside.
const double CX = 1036448.40, CY = 465018.49, VH = 532.00; // proven view from 11X17
LayoutManager.Current.CurrentLayout = "17X11";
Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("TILEMODE", 0);
var bt = (BlockTable)Tx.GetObject(Db.BlockTableId, OpenMode.ForWrite);
// ---------- 4. remove the stray viewport from the block definition
{
var def = (BlockTableRecord)Tx.GetObject(bt["SS_BLOCK_17X11"], OpenMode.ForWrite);
int killed = 0;
foreach (ObjectId id in def) {
var vp = Tx.GetObject(id, OpenMode.ForRead) as Viewport;
if (vp == null) continue;
var w = (Viewport)Tx.GetObject(id, OpenMode.ForWrite);
w.Erase();
killed++;
}
Log("stray viewports erased from SS_BLOCK_17X11: " + killed);
}
BlockTableRecord src = null, dstSheet = null;
Layout dstLay = 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") { dstSheet = (BlockTableRecord)Tx.GetObject(btrId, OpenMode.ForWrite);
dstLay = (Layout)Tx.GetObject(rec.LayoutId, OpenMode.ForWrite); }
}
if (src == null || dstSheet == null) { Log("layout missing"); return; }
// ---------- 3. media: prefer a real 17x11 landscape sheet
var psv = PlotSettingsValidator.Current;
try {
var medias = psv.GetCanonicalMediaNameList(dstLay);
string best = null;
foreach (string m in medias)
if (m.IndexOf("17.00_x_11.00", StringComparison.OrdinalIgnoreCase) >= 0) { best = m; break; }
if (best == null)
foreach (string m in medias)
if (m.IndexOf("ANSI_full_bleed_B_(11.00_x_17.00", StringComparison.OrdinalIgnoreCase) >= 0) { best = m; break; }
if (best != null) { psv.SetCanonicalMediaName(dstLay, best); Log("media -> " + best); }
else Log("no better media found; keeping " + dstLay.CanonicalMediaName);
} catch (System.Exception e) { Log("media: " + e.Message); }
// ---------- 5. reseat the block insert inside the sheet
foreach (ObjectId id in dstSheet) {
var br = Tx.GetObject(id, OpenMode.ForRead) as BlockReference;
if (br == null) continue;
var w = (BlockReference)Tx.GetObject(id, OpenMode.ForWrite);
w.Position = new Point3d(17.165, 0.165, 0);
var e = ((BlockReference)Tx.GetObject(id, OpenMode.ForRead)).GeometricExtents;
Log(string.Format("block insert -> ({0:F3},{1:F3}) ext ({2:F3},{3:F3})-({4:F3},{5:F3})",
w.Position.X, w.Position.Y, e.MinPoint.X, e.MinPoint.Y, e.MaxPoint.X, e.MaxPoint.Y));
}
// ---------- 2. copy the sheet furniture across, shifted for the landscape aspect
// portrait notes live in the right-hand strip x 7.6..10.6, y 3.5..16.6
// landscape has that room along the RIGHT of the wider sheet: shift +6.5 in X
// and drop anything that would collide with the title panel (bottom-left, x<10.5 y<3.4).
var xform = Matrix3d.Displacement(new Vector3d(6.500, 0, 0));
int copied = 0, skipped = 0;
foreach (ObjectId id in src) {
var o = Tx.GetObject(id, OpenMode.ForRead);
if (o is Viewport) continue; // viewports are made per-sheet
var srcBr = o as BlockReference;
if (srcBr != null && srcBr.Name.StartsWith("SS_BLOCK")) continue; // title block already placed
var ent = o as Autodesk.AutoCAD.DatabaseServices.Entity;
if (ent == null) continue;
var clone = ent.Clone() as Autodesk.AutoCAD.DatabaseServices.Entity;
if (clone == null) continue;
clone.TransformBy(xform);
// reject anything that lands off-sheet
try {
var e = clone.GeometricExtents;
if (e.MinPoint.X < 0.1 || e.MaxPoint.X > 17.4 || e.MinPoint.Y < 0.1 || e.MaxPoint.Y > 11.4) {
clone.Dispose(); skipped++; continue;
}
} catch { }
dstSheet.AppendEntity(clone);
Tx.AddNewlyCreatedDBObject(clone, true);
// a cloned block reference needs its attributes rebuilt
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);
}
}
copied++;
}
Log(string.Format("sheet furniture copied: {0} skipped as off-sheet: {1}", copied, skipped));
// ---------- 1. the viewport: unlock, set height AND center, then lock
foreach (ObjectId id in dstSheet) {
var vp = Tx.GetObject(id, OpenMode.ForRead) as Viewport;
if (vp == null || vp.Number == 1) continue;
var w = (Viewport)Tx.GetObject(id, OpenMode.ForWrite);
w.Locked = false; // a locked viewport recomputes the view on assignment
w.On = true;
w.ViewHeight = VH; // set height FIRST - it drives the scale
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}: view ({1:F2},{2:F2}) h={3:F2} => 1\"={4:F2}' on={5} locked={6} (verified)",
back.Number, back.ViewCenter.X, back.ViewCenter.Y, back.ViewHeight, sc>0?1.0/sc:0, back.On, back.Locked));
}
int finalCount = 0;
foreach (ObjectId id in dstSheet) finalCount++;
Log("total entities on 17X11 now: " + finalCount);
Ed.Regen();
Result
Log
stray viewports erased from SS_BLOCK_17X11: 1 media -> ANSI_B_(17.00_x_11.00_Inches) block insert -> (17.165,0.165) ext (0.165,0.165)-(17.165,11.165) sheet furniture copied: 34 skipped as off-sheet: 104 VP#2: view (1036448.40,465018.49) h=532.00 => 1"=65.30' on=True locked=True (verified) total entities on 17X11 now: 37
Notes
What worked, what didn't, job-specific gotchas — flagged notes feed the recipes.
No notes yet.