← Inbox

C3D-PSINSPECT · Inspect paper space layouts + border block (read-only) error

Layout paper size/orientation, border block name/pos/scale/rotation/extents/attribs, viewports. Plan portrait->landscape fit.

Script file
C3D-PSINSPECT.cs
Target
active document · paper space
Author
claude
Approved
yes · claude (read-only)
Timeout
60s

C# payload

// READ-ONLY: inspect paper space layouts + the border block, to plan the portrait->landscape fit.
// For each layout: plot paper size + orientation, the block references in paper space (name, position,
// scale, rotation, extents), and viewports.
using System;
using System.Linq;
using System.Collections.Generic;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;

var db = Db;
using (var tr = db.TransactionManager.StartTransaction())
{
    var ld = (DBDictionary)tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead);
    foreach (DBDictionaryEntry e in ld)
    {
        if (string.Equals(e.Key, "Model", StringComparison.OrdinalIgnoreCase)) continue;
        var lay = (Layout)tr.GetObject(e.Value, OpenMode.ForRead);
        Log($"== LAYOUT [{lay.LayoutName}] tabOrder={lay.TabOrder} ==");

        // paper size + orientation from plot settings
        try {
            var psv = new PlotSettingsValidator();
            var ext = lay.PlotPaperSize; // Point2d in mm
            Log($"   paperSize={ext.X:0.0} x {ext.Y:0.0} (mm)  orientation={(ext.X > ext.Y ? "LANDSCAPE" : "PORTRAIT")}  media='{lay.CanonicalMediaName}'");
            Log($"   plotRotation={lay.PlotRotation}  plotType={lay.PlotType}");
        } catch (System.Exception ex) { Log($"   plot read note: {ex.Message}"); }

        // entities in this layout's paper space block
        var btr = (BlockTableRecord)tr.GetObject(lay.BlockTableRecordId, OpenMode.ForRead);
        int vp = 0, blocks = 0, other = 0;
        foreach (ObjectId id in btr)
        {
            var ent = tr.GetObject(id, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Entity;
            if (ent == null) continue;
            if (ent is Viewport v && v.Number != 1)
            {
                vp++;
                Log($"   VIEWPORT #{v.Number} center=({v.CenterPoint.X:0.0},{v.CenterPoint.Y:0.0}) w={v.Width:0.0} h={v.Height:0.0}");
            }
            else if (ent is BlockReference br)
            {
                blocks++;
                var bdef = (BlockTableRecord)tr.GetObject(br.BlockTableRecord, OpenMode.ForRead);
                string ext = "?";
                try { var ge = br.GeometricExtents; ext = $"({ge.MinPoint.X:0.0},{ge.MinPoint.Y:0.0})-({ge.MaxPoint.X:0.0},{ge.MaxPoint.Y:0.0}) size {ge.MaxPoint.X-ge.MinPoint.X:0.0}x{ge.MaxPoint.Y-ge.MinPoint.Y:0.0}"; } catch {}
                Log($"   BLOCK '{bdef.Name}' at ({br.Position.X:0.0},{br.Position.Y:0.0}) scale=({br.ScaleFactors.X:0.000},{br.ScaleFactors.Y:0.000}) rot={br.Rotation*180/Math.PI:0.0}deg  extents={ext}  handle={br.Handle}  attribs={br.AttributeCollection.Count}");
            }
            else other++;
        }
        Log($"   totals: viewports={vp} blocks={blocks} other={other}");
    }
    tr.Commit();
}

Result

Status
error
Drawing file
C:\Users\sanja\OneDrive\_SurveyDisco\260613 - 5030 E Lake Pkwy, Stockbridge, GA 30281, USA\SS_Outfall_260612_SHEET.dwg
Message
Compile error: (22,27): error CS1729: 'PlotSettingsValidator' does not contain a constructor that takes 0 arguments
Entities
Duration
351 ms
Civil 3D
25.0.0.0

Notes

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

No notes yet.