← Inbox

C3D-0272 · 260714 Huckaby: shift the whole 17X11 sheet onto the paper done

The paper occupies layout coords x -0.250..16.750, y -0.750..10.250 but the border sat at 0.330..16.670 / 0.330..10.670, overhanging the top and right. Translates every sheet entity by (-0.250,-0.750) so the 16.34x10.34 border lands inside the paper with clearance on all four sides. No rescale - the block is already the right size. Verifies the full content bounds against the paper bounds.

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

C# payload

// Put the whole sheet inside the paper.
// Paper occupies layout coords x -0.250..16.750, y -0.750..10.250.
// Target frame, 0.33 inside the paper on all sides:
//     x  0.080 .. 16.420      y -0.420 ..  9.920
// The block definition is 16.34 x 10.34, which is exactly 16.340 x 10.340 - the target frame is
// 16.340 x 10.340. So NO rescale is needed: only a translation.
//   current border  x 0.330..16.670  y 0.330..10.670
//   target border   x 0.080..16.420  y -0.420..9.920
//   => dx = -0.250, dy = -0.750
// Everything on the sheet moves by the same vector so the layout keeps its relative arrangement.
const double DX = -0.250, DY = -0.750;

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;

    var move = Matrix3d.Displacement(new Vector3d(DX, DY, 0));
    int n = 0;
    foreach (ObjectId id in rec) {
        var ent = Tx.GetObject(id, OpenMode.ForWrite) as Autodesk.AutoCAD.DatabaseServices.Entity;
        if (ent == null) continue;
        var vp = ent as Viewport;
        if (vp != null && vp.Number == 1) continue;         // paper background, not real geometry
        try { ent.TransformBy(move); n++; } catch { }
    }
    Log(string.Format("moved {0} sheet entities by ({1:F3},{2:F3})", n, DX, DY));

    // report against the paper
    double pw = lay.PlotPaperSize.X/25.4, ph = lay.PlotPaperSize.Y/25.4;
    var m = lay.PlotPaperMargins;
    double px0 = -m.MinPoint.X/25.4, py0 = -m.MinPoint.Y/25.4;
    double px1 = px0 + pw, py1 = py0 + ph;
    Log(string.Format("PAPER x {0:F3}..{1:F3}  y {2:F3}..{3:F3}", px0, px1, py0, py1));

    double ax0=1e30, ay0=1e30, ax1=-1e30, ay1=-1e30;
    foreach (ObjectId id in rec) {
        var ent = Tx.GetObject(id, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Entity;
        if (ent == null) continue;
        var vp = ent as Viewport;
        if (vp != null && vp.Number == 1) continue;
        try {
            var e = ent.GeometricExtents;
            if (e.MinPoint.X < ax0) ax0 = e.MinPoint.X;
            if (e.MinPoint.Y < ay0) ay0 = e.MinPoint.Y;
            if (e.MaxPoint.X > ax1) ax1 = e.MaxPoint.X;
            if (e.MaxPoint.Y > ay1) ay1 = e.MaxPoint.Y;
        } catch { }
        var br = ent as BlockReference;
        if (br != null) {
            var e2 = br.GeometricExtents;
            Log(string.Format("  {0,-16} ({1:F3},{2:F3})-({3:F3},{4:F3})", br.Name,
                e2.MinPoint.X, e2.MinPoint.Y, e2.MaxPoint.X, e2.MaxPoint.Y));
        }
    }
    Log(string.Format("ALL SHEET CONTENT x {0:F3}..{1:F3}  y {2:F3}..{3:F3}", ax0, ax1, ay0, ay1));
    bool fits = ax0 >= px0 - 0.001 && ax1 <= px1 + 0.001 && ay0 >= py0 - 0.001 && ay1 <= py1 + 0.001;
    Log("EVERYTHING ON THE PAPER: " + (fits ? "YES" : "NO") + " (verified)");
    if (!fits) Log(string.Format("  overhang L{0:F3} R{1:F3} B{2:F3} T{3:F3}",
        px0-ax0, ax1-px1, py0-ay0, ay1-py1));
}
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-0272 (0 entities touched).
Entities
Duration
673 ms
Civil 3D
25.0.0.0

Log

moved 138 sheet entities by (-0.250,-0.750)
PAPER x -0.250..16.750  y -0.750..10.250
  SS_BLOCK_17X11   (-0.007,-0.420)-(16.420,9.920)
  SS_LEGEND        (13.841,7.021)-(16.545,10.229)
ALL SHEET CONTENT x -0.007..19.220  y -0.420..12.666
EVERYTHING ON THE PAPER: NO (verified)
  overhang L-0.243 R2.470 B-0.330 T2.416

Notes

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

No notes yet.