C3D-PSINSPECT2 · Inspect paper space v2 (read-only) done
Layout paper size/orientation, border block, viewports.
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 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
Log
== LAYOUT [11X17] tabOrder=1 == paperSize=279.4 x 431.8 (mm) orientation=PORTRAIT media='ANSI_B_(11.00_x_17.00_Inches)' plotRotation=Degrees090 plotType=Layout VIEWPORT #2 center=(7.8,5.3) w=17.5 h=11.7 BLOCK 'SS_LEGEND' at (16.1,13.0) scale=(1.000,1.000) rot=0.0deg extents=(12.8,13.2)-(15.5,16.4) size 2.7x3.2 handle=1DE4 attribs=0 BLOCK 'SS_BLOCK_11X17' at (16.0,0.1) scale=(1.000,1.000) rot=0.0deg extents=(5.4,0.1)-(16.0,16.6) size 10.6x16.5 handle=1DE5 attribs=10 totals: viewports=1 blocks=2 other=139
Notes
What worked, what didn't, job-specific gotchas — flagged notes feed the recipes.
No notes yet.