← Inbox

C3D-PSDETAIL · Border geometry detail + cleanup scope (read-only) done

Border insertion vs extents, paper margins, attribute tags, and the 139 other PS entities by type/layer.

Script file
C3D-PSDETAIL.cs
Target
active document · paper space
Author
claude
Approved
yes · auto-auth
Timeout
60s

C# payload

// READ-ONLY: precise geometry for the portrait->landscape border fix on layout 11X17.
// - the border block's base/insertion vs its extents (is base a corner or offset?)
// - paper printable-area limits (Layout.Limits / PlotPaperMargins) to know target frame
// - what the 139 "other" paper-space entities are (types + layers), for cleanup scoping
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);
    Layout lay = null;
    foreach (DBDictionaryEntry e in ld)
    {
        var l = (Layout)tr.GetObject(e.Value, OpenMode.ForRead);
        if (string.Equals(l.LayoutName, "11X17", StringComparison.OrdinalIgnoreCase)) { lay = l; break; }
    }
    if (lay == null) { Log("11X17 not found"); tr.Commit(); return; }

    Log($"Layout limits: min=({lay.Limits.MinPoint.X:0.00},{lay.Limits.MinPoint.Y:0.00}) max=({lay.Limits.MaxPoint.X:0.00},{lay.Limits.MaxPoint.Y:0.00})");
    try { Log($"PlotOrigin=({lay.PlotOrigin.X:0.000},{lay.PlotOrigin.Y:0.000})  PlotPaperUnits={lay.PlotPaperUnits}"); } catch {}
    try { var m = lay.PlotPaperMargins; Log($"margins min=({m.MinPoint.X:0.0},{m.MinPoint.Y:0.0}) max=({m.MaxPoint.X:0.0},{m.MaxPoint.Y:0.0}) (mm)"); } catch {}

    var btr = (BlockTableRecord)tr.GetObject(lay.BlockTableRecordId, OpenMode.ForRead);

    // border block detail
    foreach (ObjectId id in btr)
    {
        var br = tr.GetObject(id, OpenMode.ForRead) as BlockReference;
        if (br == null) continue;
        var bdef = (BlockTableRecord)tr.GetObject(br.BlockTableRecord, OpenMode.ForRead);
        if (!bdef.Name.Contains("11X17")) continue;
        var ge = br.GeometricExtents;
        Log($"BORDER '{bdef.Name}' insertion=({br.Position.X:0.000},{br.Position.Y:0.000})");
        Log($"   block-def origin=({bdef.Origin.X:0.000},{bdef.Origin.Y:0.000})");
        Log($"   extents min=({ge.MinPoint.X:0.000},{ge.MinPoint.Y:0.000}) max=({ge.MaxPoint.X:0.000},{ge.MaxPoint.Y:0.000})");
        Log($"   insertion vs extents: dx_min={br.Position.X-ge.MinPoint.X:0.00} dy_min={br.Position.Y-ge.MinPoint.Y:0.00}");
        // attribute tags (so we know what fields exist, for tomorrow)
        foreach (ObjectId aid in br.AttributeCollection)
        {
            var ar = tr.GetObject(aid, OpenMode.ForRead) as AttributeReference;
            if (ar != null) Log($"   ATTR {ar.Tag} = '{ar.TextString}'");
        }
    }

    // the 139 "other" entities: count by type+layer
    var byType = new SortedDictionary<string,int>(StringComparer.OrdinalIgnoreCase);
    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 || ent is BlockReference) continue;
        var key = $"{ent.GetType().Name} @ {ent.Layer}";
        byType[key] = byType.TryGetValue(key, out var c) ? c+1 : 1;
    }
    Log("OTHER paper-space entities (type @ layer):");
    foreach (var kv in byType) Log($"   {kv.Value}x  {kv.Key}");
    tr.Commit();
}

Result

Status
success
Drawing file
C:\Users\sanja\OneDrive\_SurveyDisco\260613 - 5030 E Lake Pkwy, Stockbridge, GA 30281, USA\SS_Outfall_260612_SHEET.dwg
Message
Executed C3D-PSDETAIL (0 entities touched).
Entities
Duration
454 ms
Civil 3D
25.0.0.0

Log

Layout limits: min=(-0.67,-0.20) max=(16.33,10.80)
PlotOrigin=(0.000,0.000)  PlotPaperUnits=Inches
margins min=(5.0,17.0) max=(5.0,17.0) (mm)
BORDER 'SS_BLOCK_11X17' insertion=(16.049,0.097)
   block-def origin=(0.000,0.000)
   extents min=(5.399,0.097) max=(16.049,16.574)
   insertion vs extents: dx_min=10.65 dy_min=0.00
   ATTR JOB_NO = 'JOB NO.: 260702'
   ATTR SITE_ADDRESS = '358 Saint Johns Avenue, Atlanta, Georgia 30315'
   ATTR REF_DB_PG = 'REF DB 27530 Page 262'
   ATTR LAND_LOT = 'LAND LOT: 90'
   ATTR DISTRICT = 'DISTRICT: 14th'
   ATTR COUNTY = 'COUNTY: Fulton'
   ATTR DATE = 'DATE: 07/16/26'
   ATTR SUBDIVISION_NAME_LOT = 'Lakewood Heights'
   ATTR PREP_FOR = 'HOUSTON RESIDENTIAL RENTALS LLC'
   ATTR SURVEY_TYPE = 'Survey'
OTHER paper-space entities (type @ layer):
   1x  Arc @ BLOCK_CLOSURE
   2x  Arc @ BLOCK_NORTH_ARROW
   8x  DBText @ BLOCK_CLOSURE
   1x  DBText @ BLOCK_NORTH_ARROW
   12x  Line @ BLOCK_CLOSURE
   90x  Line @ BLOCK_NORTH_ARROW
   2x  Line @ TB1
   1x  MText @ BLOCK_CLOSURE
   2x  MText @ BLOCK_NOTES_FLOOD
   4x  Polyline @ BLOCK_CLOSURE
   1x  Polyline @ SS-BOUNDARY CYAN
   2x  Polyline2d @ BLOCK_CLOSURE
   8x  Polyline2d @ BLOCK_NORTH_ARROW
   4x  Solid @ BLOCK_CLOSURE

Notes

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

No notes yet.