← Inbox

C3D-0234 · 260612 Springdale: move the title block to the top of SS_BLOCK_11X17 done

Edits the BLOCK DEFINITION: translates the 37 title-block entities (everything below y=2.95, including all 10 attribute definitions) up by dy=13.503 so the title block sits flush with the sheet top border at y=16.434. The sheet border, right-edge lines and the viewport are left in place. Verifies the resulting y range on read-back, regen last. Existing inserts will need ATTSYNC to pick up the new attribute positions.

Script file
C3D-0234.cs
Target
260612-Springdale Sanitary Sewer Extension As-Built 60.dwg · model space
Author
claude
Approved
yes · auto-auth
Timeout
60s

C# payload

// Move the title block inside the SS_BLOCK_11X17 DEFINITION from the bottom of the sheet to
// the top. The block spans y 0 -> 16.477; the title block is the band below y=2.95 and there is
// nothing between it and the border, so it is a clean vertical translation.
//
// DY puts the title block's top edge (2.931) flush with the sheet's inner border (16.434).
//
// The 9 entities NOT moved are the sheet border, the right-edge segments and the viewport -
// they span the full sheet height and are not part of the title block.
//
// Editing the block DEFINITION updates every insert. Attribute REFERENCES on existing inserts
// keep their old positions until ATTSYNC is run (learned on 260806).
const double TB_TOP = 2.95;      // title band is everything at/below this y
const double DY     = 13.503;    // 16.434 - 2.931

var bt = (BlockTable)Tx.GetObject(Db.BlockTableId, OpenMode.ForRead);
if (!bt.Has("SS_BLOCK_11X17")) { Log("SS_BLOCK_11X17 not found"); return; }
var btr = (BlockTableRecord)Tx.GetObject(bt["SS_BLOCK_11X17"], OpenMode.ForWrite);

var xform = Matrix3d.Displacement(new Vector3d(0, DY, 0));
int moved = 0, kept = 0;
var mover = new List<Autodesk.AutoCAD.DatabaseServices.Entity>();

foreach (ObjectId id in btr) {
    Autodesk.AutoCAD.DatabaseServices.DBObject o;
    try { o = Tx.GetObject(id, OpenMode.ForWrite); } catch { continue; }
    var ent = o as Autodesk.AutoCAD.DatabaseServices.Entity;
    if (ent == null) continue;

    // An AttributeDefinition reports empty extents, so decide on its insertion point.
    var ad = ent as AttributeDefinition;
    if (ad != null) {
        if (ad.Position.Y <= TB_TOP) { mover.Add(ent); } else { kept++; }
        continue;
    }
    // Viewport is the drawing window - never move it.
    if (ent is Viewport) { kept++; continue; }

    double top;
    try { top = ent.GeometricExtents.MaxPoint.Y; }
    catch { kept++; continue; }

    if (top <= TB_TOP) mover.Add(ent); else kept++;
}

foreach (var ent in mover) {
    ent.TransformBy(xform);
    moved++;
}

Log(string.Format("moved {0} title-block entities by dy={1:F3}; left {2} in place (border/viewport)",
    moved, DY, kept));

// verify: re-read the band that is now supposed to be empty at the bottom
int stillLow = 0;
double newMin = 1e30, newMax = -1e30;
foreach (ObjectId id in btr) {
    var ent = Tx.GetObject(id, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Entity;
    if (ent == null) continue;
    var ad = ent as AttributeDefinition;
    if (ad != null) {
        if (ad.Position.Y < newMin) newMin = ad.Position.Y;
        if (ad.Position.Y > newMax) newMax = ad.Position.Y;
        if (ad.Position.Y <= TB_TOP) stillLow++;
        continue;
    }
    if (ent is Viewport) continue;
    try {
        var e = ent.GeometricExtents;
        if (e.MinPoint.Y < newMin) newMin = e.MinPoint.Y;
        if (e.MaxPoint.Y > newMax) newMax = e.MaxPoint.Y;
    } catch { }
}
Log(string.Format("after: attribute/geometry y range {0:F3} .. {1:F3}; attributes left below {2:F2}: {3} (verified)",
    newMin, newMax, TB_TOP, stillLow));
Ed.Regen();

Result

Status
success
Drawing file
C:\Users\sanja\OneDrive\_SurveyDisco\260613 - 5030 E Lake Pkwy, Stockbridge, GA 30281, USA\260612-Springdale Sanitary Sewer Extension As-Built 60 wPROFILE.dwg
Message
Executed C3D-0234 (0 entities touched).
Entities
Duration
550 ms
Civil 3D
25.0.0.0

Log

moved 37 title-block entities by dy=13.503; left 9 in place (border/viewport)
after: attribute/geometry y range 0.000 .. 16.477; attributes left below 2.95: 0 (verified)

Notes

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

No notes yet.