← Inbox

C3D-0248 · 260714 Huckaby: fill the 17X11 title block and frame its viewport done

Copies the 13 title block attribute values from the 11X17 sheet onto the 17X11 sheet (same job) and points the landscape viewport at the same model view and scale as the portrait one, then locks it. Verifies every attribute and the viewport state on read-back.

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

C# payload

// Fill the 17X11 title block from the 11X17 sheet (same job, so the values are identical) and
// frame its viewport on the same view the portrait sheet shows.
var bt = (BlockTable)Tx.GetObject(Db.BlockTableId, OpenMode.ForRead);

// ---- harvest the source values + view from the 11X17 layout
var vals = new Dictionary<string, string>();
Point3d srcCenter = Point3d.Origin;
double srcHeight = 0, srcScale = 0;
bool gotView = false;

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 != "11X17") continue;
    foreach (ObjectId id in rec) {
        var o = Tx.GetObject(id, OpenMode.ForRead);
        var br = o as BlockReference;
        if (br != null) {
            foreach (ObjectId aid in br.AttributeCollection) {
                var ar = Tx.GetObject(aid, OpenMode.ForRead) as AttributeReference;
                if (ar != null && !vals.ContainsKey(ar.Tag)) vals[ar.Tag] = ar.TextString;
            }
        }
        var vp = o as Viewport;
        if (vp != null && vp.Number != 1 && !gotView) {
            srcCenter = new Point3d(vp.ViewCenter.X, vp.ViewCenter.Y, 0);
            srcHeight = vp.ViewHeight;
            try { srcScale = vp.CustomScale; } catch { }
            gotView = true;
        }
    }
}
Log(string.Format("source: {0} attribute values, view center ({1:F2},{2:F2}) height {3:F2} scale {4:F6}",
    vals.Count, srcCenter.X, srcCenter.Y, srcHeight, srcScale));

// ---- apply to the 17X11 sheet
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;

    foreach (ObjectId id in rec) {
        var o = Tx.GetObject(id, OpenMode.ForRead);

        var br = o as BlockReference;
        if (br != null) {
            int set = 0;
            foreach (ObjectId aid in br.AttributeCollection) {
                var ar = Tx.GetObject(aid, OpenMode.ForWrite) as AttributeReference;
                if (ar == null) continue;
                string v;
                if (vals.TryGetValue(ar.Tag, out v)) { ar.TextString = v; set++; }
            }
            Log("filled " + set + " attributes on the 17X11 title block");
            foreach (ObjectId aid in br.AttributeCollection) {
                var ar = Tx.GetObject(aid, OpenMode.ForRead) as AttributeReference;
                if (ar != null) Log(string.Format("   {0,-22} = \"{1}\"", ar.Tag, ar.TextString));
            }
            continue;
        }

        var vp = o as Viewport;
        if (vp != null && vp.Number != 1 && gotView) {
            var w = (Viewport)Tx.GetObject(vp.ObjectId, OpenMode.ForWrite);
            w.On = true;
            w.ViewCenter = new Point2d(srcCenter.X, srcCenter.Y);
            if (srcScale > 0) w.CustomScale = srcScale;
            w.Locked = true;
            var back = (Viewport)Tx.GetObject(vp.ObjectId, OpenMode.ForRead);
            Log(string.Format("viewport: center ({0:F2},{1:F2}) height {2:F2} scale {3:F6} => 1\"={4:F2}' on={5} locked={6} (verified)",
                back.ViewCenter.X, back.ViewCenter.Y, back.ViewHeight, back.CustomScale,
                back.CustomScale > 0 ? 1.0 / back.CustomScale : 0, back.On, back.Locked));
        }
    }
}
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-0248 (0 entities touched).
Entities
Duration
347 ms
Civil 3D
25.0.0.0

Log

source: 13 attribute values, view center (1036448.40,465018.49) height 532.00 scale 0.030776
filled 13 attributes on the 17X11 title block
   JOB_NO                 = "JOB NO.: 260714"
   SITE_ADDRESS           = "285 Huckaby Rd, Brooks, GA 30205, USA"
   REF_DB_PG              = "REF DB 5857 Page 692"
   LAND_LOT               = "LAND LOT: 124"
   DISTRICT               = "DISTRICT: 4th"
   COUNTY                 = "COUNTY: Fayette"
   DATE                   = "DATE: 08/13/26"
   SUBDIVISION_NAME_LOT   = ""
   PREP_FOR               = "JOY EWING"
   SURVEY_TYPE            = "Boundary Survey"
   FIRM_PANEL             = "13113C0155E,"
   FIRM_DATE              = "EFFECTIVE SEPTEMBER 26, 2008,"
   FLOOD_ZONE             = "AND LIES IN ZONE X."

Notes

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

No notes yet.