← Inbox

C3D-0252 · 260714 Huckaby: point the 17X11 viewport at the property done

C3D-0251 copied the paper background pseudo-viewport instead of the real one, leaving the landscape viewport at 1inch=1foot on sheet coordinates. Sets it explicitly to the 11X17 sheets view: center 1036448.40,465018.49 at customScale 0.030776 (1inch=32.49feet), on and locked. Distinguishes the real viewport from the background by whether its view center is in model coordinates.

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

C# payload

// C3D-0251 read viewport #1 (the paper background pseudo-viewport) instead of the real one,
// because after switching the current layout the iteration order changed. Set the 17X11
// viewport explicitly to the known-good view from the 11X17 sheet:
//     center (1036448.40, 465018.49), customScale 0.030776  => 1" = 32.49'
const double CX = 1036448.40, CY = 465018.49, SCALE = 0.030776;

LayoutManager.Current.CurrentLayout = "17X11";
Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("TILEMODE", 0);

var bt = (BlockTable)Tx.GetObject(Db.BlockTableId, OpenMode.ForRead);
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;

    foreach (ObjectId id in rec) {
        var vp = Tx.GetObject(id, OpenMode.ForRead) as Viewport;
        if (vp == null) continue;
        // skip the paper background: it is the one whose view center is in sheet coordinates
        if (Math.Abs(vp.ViewCenter.X) < 1000.0) {
            Log(string.Format("skipping paper-background viewport #{0} (viewCenter {1:F2},{2:F2})",
                vp.Number, vp.ViewCenter.X, vp.ViewCenter.Y));
            continue;
        }
        var w = (Viewport)Tx.GetObject(id, OpenMode.ForWrite);
        w.ViewCenter = new Point2d(CX, CY);
        w.CustomScale = SCALE;
        w.On = true;
        w.Locked = true;
        var back = (Viewport)Tx.GetObject(id, OpenMode.ForRead);
        Log(string.Format("VIEWPORT#{0}: view ({1:F2},{2:F2}) height {3:F2} scale {4:F6} => 1\"={5:F2}' on={6} locked={7} (verified)",
            back.Number, back.ViewCenter.X, back.ViewCenter.Y, back.ViewHeight,
            back.CustomScale, 1.0/back.CustomScale, back.On, back.Locked));
    }
    // if the only viewport we saw was the background, the real one needs its view set anyway
    foreach (ObjectId id in rec) {
        var vp = Tx.GetObject(id, OpenMode.ForRead) as Viewport;
        if (vp == null || vp.Number == 1) continue;
        if (Math.Abs(vp.ViewCenter.X) >= 1000.0) continue;
        var w = (Viewport)Tx.GetObject(id, OpenMode.ForWrite);
        w.ViewCenter = new Point2d(CX, CY);
        w.CustomScale = SCALE;
        w.On = true;
        w.Locked = true;
        var back = (Viewport)Tx.GetObject(id, OpenMode.ForRead);
        Log(string.Format("VIEWPORT#{0} (repointed): view ({1:F2},{2:F2}) height {3:F2} => 1\"={4:F2}' (verified)",
            back.Number, back.ViewCenter.X, back.ViewCenter.Y, back.ViewHeight, 1.0/back.CustomScale));
    }
}
Ed.Regen();

Result

Status
success
Drawing file
C:\Users\sanja\OneDrive\_SurveyDisco\260714 - 285 Huckaby Rd, Brooks, GA 30205, USA\260714 - 285 Huckaby Rd.dwg
Message
Executed C3D-0252 (0 entities touched).
Entities
Duration
973 ms
Civil 3D
25.0.0.0

Log

skipping paper-background viewport #1 (viewCenter 7.71,4.50)
skipping paper-background viewport #2 (viewCenter 13.83,10.02)
VIEWPORT#2 (repointed): view (1036448.40,465018.49) height 264.72 => 1"=32.49' (verified)

Notes

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

No notes yet.