← Inbox

C3D-0336 · 17X11: read the viewport view (ViewCenter, ViewHeight, scale) and model extents [C3D-VPREAD] done

Read-only. Reports the 17X11 viewport's frame on the sheet, its ViewCenter/ViewHeight/scale, the exact model window it currently shows in feet, and the model-space extents. Needed to compute the pan that clears the 3x3 corner notch without touching the viewport frame.

Script file
C3D-0336.cs
Target
260714 - 285 Huckaby Rd R3.dwg · paper space
Author
claude
Approved
yes · auto-auth
Timeout
120s

C# payload

// The 17X11 viewport's current view, and where the drawing actually sits inside it, so the
// pan needed to clear the 3x3 notch can be computed instead of guessed.
Log("drawing: " + Db.Filename);

var dict = (DBDictionary)Tx.GetObject(Db.LayoutDictionaryId, OpenMode.ForRead);
foreach (DBDictionaryEntry de in dict) {
    var lay = (Layout)Tx.GetObject(de.Value, OpenMode.ForRead);
    if (lay.LayoutName != "17X11") continue;
    var btr = (BlockTableRecord)Tx.GetObject(lay.BlockTableRecordId, OpenMode.ForRead);
    foreach (ObjectId eid in btr) {
        var vp = Tx.GetObject(eid, OpenMode.ForRead) as Viewport;
        if (vp == null) continue;
        if (vp.Number == 1) { Log("VP [" + vp.Handle + "] is the paper-space vp, skipping"); continue; }

        Autodesk.AutoCAD.DatabaseServices.Extents3d ex;
        try { ex = vp.GeometricExtents; } catch { continue; }
        Log(string.Format("VIEWPORT [{0}] num={1} on={2} locked={3}", vp.Handle, vp.Number, vp.On, vp.Locked));
        Log(string.Format("   frame on sheet : ({0:F4},{1:F4}) - ({2:F4},{3:F4})   {4:F4} x {5:F4}",
            ex.MinPoint.X, ex.MinPoint.Y, ex.MaxPoint.X, ex.MaxPoint.Y,
            ex.MaxPoint.X-ex.MinPoint.X, ex.MaxPoint.Y-ex.MinPoint.Y));
        Log(string.Format("   Width/Height   : {0:F4} x {1:F4}   CenterPoint ({2:F4},{3:F4})",
            vp.Width, vp.Height, vp.CenterPoint.X, vp.CenterPoint.Y));
        Log(string.Format("   ViewCenter     : ({0:F4},{1:F4})", vp.ViewCenter.X, vp.ViewCenter.Y));
        Log(string.Format("   ViewHeight     : {0:F4}   CustomScale={1:F6}", vp.ViewHeight, vp.CustomScale));
        Log(string.Format("   ViewTarget     : ({0:F4},{1:F4},{2:F4})", vp.ViewTarget.X, vp.ViewTarget.Y, vp.ViewTarget.Z));
        Log(string.Format("   TwistAngle     : {0:F4}", vp.TwistAngle));

        // model window currently shown
        double vw = vp.ViewHeight * (vp.Width / vp.Height);
        double mx0 = vp.ViewCenter.X - vw/2, mx1 = vp.ViewCenter.X + vw/2;
        double my0 = vp.ViewCenter.Y - vp.ViewHeight/2, my1 = vp.ViewCenter.Y + vp.ViewHeight/2;
        Log(string.Format("   MODEL WINDOW   : x {0:F2}..{1:F2}  y {2:F2}..{3:F2}   ({4:F2} x {5:F2} ft)",
            mx0, mx1, my0, my1, vw, vp.ViewHeight));
        Log(string.Format("   scale          : 1in = {0:F2} ft   ({1:F4} ft per paper inch)",
            vp.ViewHeight / vp.Height, vp.ViewHeight / vp.Height));
        Log(string.Format("   ft per inch    : {0:F4}", vp.ViewHeight / vp.Height));
    }
}

// model space extents so we know how much slack there is
Log("");
var ms = (BlockTableRecord)Tx.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(Db), OpenMode.ForRead);
double X0=1e30,Y0=1e30,X1=-1e30,Y1=-1e30; int cnt=0;
foreach (ObjectId id in ms) {
    var e = Tx.GetObject(id, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Entity;
    if (e == null || e.IsErased) continue;
    if (!e.Visible) continue;
    Autodesk.AutoCAD.DatabaseServices.Extents3d ex;
    try { ex = e.GeometricExtents; } catch { continue; }
    if (ex.MinPoint.X < -1e10 || ex.MaxPoint.X > 1e10) continue;
    X0=Math.Min(X0,ex.MinPoint.X); Y0=Math.Min(Y0,ex.MinPoint.Y);
    X1=Math.Max(X1,ex.MaxPoint.X); Y1=Math.Max(Y1,ex.MaxPoint.Y);
    cnt++;
}
Log(string.Format("MODEL EXTENTS ({0} ents): x {1:F2}..{2:F2}  y {3:F2}..{4:F2}   ({5:F2} x {6:F2} ft)",
    cnt, X0, X1, Y0, Y1, X1-X0, Y1-Y0));

Result

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

Log

drawing: C:\Users\sanja\OneDrive\_SurveyDisco\260714 - 285 Huckaby Rd, Brooks, GA 30205, USA\260714 - 285 Huckaby Rd R3.dwg
VP [20E70] is the paper-space vp, skipping
VIEWPORT [20E73] num=2 on=True locked=True
   frame on sheet : (0.3733,0.3707) - (16.6284,10.6296)   16.2551 x 10.2589
   Width/Height   : 16.2551 x 10.2589   CenterPoint (8.5008,5.5002)
   ViewCenter     : (2204922.3227,1206632.6191)
   ViewHeight     : 2051.7701   CustomScale=0.005000
   ViewTarget     : (0.0000,0.0000,0.0000)
   TwistAngle     : 0.0000
   MODEL WINDOW   : x 2203296.81..2206547.83  y 1205606.73..1207658.50   (3251.02 x 2051.77 ft)
   scale          : 1in = 200.00 ft   (200.0000 ft per paper inch)
   ft per inch    : 200.0000

MODEL EXTENTS (174 ents): x 0.00..2216390.00  y 0.00..1215195.56   (2216390.00 x 1215195.56 ft)

Notes

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

No notes yet.