← Inbox

C3D-0250 · 260714 Huckaby: create the 17X11 paper-space viewport error

The 11X17 sheets real viewport is a paper-space entity, not the one inside the block definition, so the new landscape layout had none. Creates a viewport filling the sheet above the title panel (x 0.333-17.247, y 3.100-11.247), points it at the same model view and scale as the portrait sheet, turns it on and locks it. Verifies on read-back.

Script file
C3D-0250.cs
Target
260714 - 285 Huckaby Rd.dwg · model space
Author
claude
Approved
yes · auto-auth
Timeout
60s

C# payload

// The 11X17 sheet's real viewport is a PAPER SPACE entity (#2), not the one inside the block
// definition. 17X11 was created with none, so make one: it must fill the sheet above the
// title panel, and show the same model view at the same scale as the portrait sheet.
//
// Sheet占 the block insert spans (0.290,0.290)-(17.290,11.290).
// Title panel inside the block occupies the bottom ~2.71 + the flood note to ~3.10,
// anchored bottom-left -> in sheet coords roughly x 0.29..10.49, y 0.29..3.39.
// So the viewport gets the full width above the panel.
var bt = (BlockTable)Tx.GetObject(Db.BlockTableId, OpenMode.ForRead);

// source view from 11X17
Point2d ctr = new Point2d(); double scale = 0; bool got = false;
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") continue;
    foreach (ObjectId id in rec) {
        var vp = Tx.GetObject(id, OpenMode.ForRead) as Viewport;
        if (vp == null || vp.Number == 1) continue;
        ctr = vp.ViewCenter; try { scale = vp.CustomScale; } catch { }
        got = true; break;
    }
}
if (!got) { Log("could not read the 11X17 viewport"); return; }
Log(string.Format("source view center ({0:F2},{1:F2}) scale {2:F6} => 1\"={3:F2}'", ctr.X, ctr.Y, scale, 1.0/scale));

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 != "17X11") continue;

    var sheet = (BlockTableRecord)Tx.GetObject(rec.ObjectId, OpenMode.ForWrite);

    // area above the title panel, inside the border
    double x0 = 0.333, x1 = 17.247;      // block inner edges in sheet coords
    double y0 = 3.100, y1 = 11.247;      // above the flood note, up to the inner top border
    var vp = new Viewport();
    vp.Width = x1 - x0;
    vp.Height = y1 - y0;
    vp.CenterPoint = new Point3d((x0 + x1) / 2.0, (y0 + y1) / 2.0, 0);
    vp.Layer = "BLOCK_TB2";
    sheet.AppendEntity(vp);
    Tx.AddNewlyCreatedDBObject(vp, true);

    vp.On = true;                         // must be appended to the db before turning on
    vp.ViewCenter = ctr;
    if (scale > 0) vp.CustomScale = scale;
    vp.Locked = true;

    var back = (Viewport)Tx.GetObject(vp.ObjectId, OpenMode.ForRead);
    Log(string.Format("VIEWPORT#{0} created: paper center ({1:F3},{2:F3}) size {3:F3} x {4:F3}",
        back.Number, back.CenterPoint.X, back.CenterPoint.Y, back.Width, back.Height));
    Log(string.Format("   view center ({0:F2},{1:F2}) height {2:F2} scale {3:F6} => 1\"={4:F2}'  on={5} locked={6} (verified)",
        back.ViewCenter.X, back.ViewCenter.Y, back.ViewHeight, back.CustomScale,
        back.CustomScale > 0 ? 1.0/back.CustomScale : 0, back.On, back.Locked));
}
Ed.Regen();

Result

Status
error
Drawing file
C:\Users\sanja\OneDrive\_SurveyDisco\260714 - 285 Huckaby Rd, Brooks, GA 30205, USA\260714 - 285 Huckaby Rd.dwg
Message
eNotInPaperspace
Entities
Duration
325 ms
Civil 3D
25.0.0.0

Log

source view center (1036448.40,465018.49) scale 0.030776 => 1"=32.49'

Notes

What worked, what didn't, job-specific gotchas — flagged notes feed the recipes.

No notes yet.