← Inbox

C3D-PDFSTRIP · Strip PDF block to HCWA-required layers rejected

Erases contours, grading, title block and sheet furniture from inside the PDF block definition; keeps sewer/water/hydrant/easement/boundary/road/building/annotation geometry per the HCWA CAD Layers table.

Script file
C3D-PDFSTRIP.cs
Target
active document · model space
Author
claude
Approved
no
Timeout
60s

C# payload

// Strip the PDF block down to only what HCWA requires. Erases entities inside the block
// definition whose PDF layer maps to nothing in the HCWA CAD Layers table (contours, grading,
// title block, sheet furniture, hatch patterns), and keeps the utility/road/boundary geometry.
// Keep-list is derived from the HCWA required-layer table:
//   ROAD_EDGE_OF_PAVEMENT / ROAD_RIGHT-OF-WAY / ROAD_TEXT / PROJECT_BOUNDARY / PROPERTY_LINE /
//   SEWER_* / WATER_* / FIRE_HYDRANT* / *_EASEMENT / LAND_LOT_LINE / ADDRESS_TEXT
var bt = (BlockTable)Tx.GetObject(Db.BlockTableId, OpenMode.ForRead);
BlockTableRecord def = null;
foreach (ObjectId id in bt) {
    var b = (BlockTableRecord)Tx.GetObject(id, OpenMode.ForRead);
    if (b.Name.Contains("As Built") || b.Name.Contains("DEV3896")) { def = b; break; }
}
if (def == null) { Log("block def not found"); return; }

// KEEP if the PDF layer name contains any of these tokens (case-insensitive)
string[] keep = {
    "SSWR","SEWER","SS-",  "PIPE-SS",            // sewer
    "WATR","WATER","WTR",                        // water
    "HYDR","FH",                                 // hydrants
    "ESMT","EASEMENT",                           // easements
    "BNDY","BOUND","PROP","PARCEL","LOT",        // boundary / property / lot
    "ROAD","CURB","PAVE","EOP","RW","R-W","SIDEWLK","SIDEWALK","STRIPE","MRKG", // roads
    "BLDG","BUILDING",                           // buildings
    "TEXT","ANNO","LABEL",                       // annotation (road names, addresses)
    "STRM","STORM",                              // storm (client deliverable, not HCWA)
};
// but always DROP these, even if they match above
string[] drop = {
    "CONTOUR","PGRADE","GRADE","TBORDER","TITLE","T-BD","SEAL","GRAPHIC_SCALE","LOGO",
    "-PATT","HATCH","VIEWPORT","DEFPOINTS","NORTH",
};

bool Keep(string lay) {
    var u = lay.ToUpperInvariant();
    foreach (var d in drop) if (u.Contains(d)) return false;
    foreach (var k in keep) if (u.Contains(k)) return true;
    return false;
}

var toErase = new List<ObjectId>();
var keptTally = new Dictionary<string,int>();
var dropTally = new Dictionary<string,int>();
foreach (ObjectId id in def) {
    var e = Tx.GetObject(id, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Entity;
    if (e == null) continue;
    if (Keep(e.Layer)) keptTally[e.Layer] = keptTally.TryGetValue(e.Layer, out var a) ? a+1 : 1;
    else { dropTally[e.Layer] = dropTally.TryGetValue(e.Layer, out var b) ? b+1 : 1; toErase.Add(id); }
}
Log("=== KEEPING ===");
foreach (var kv in keptTally.OrderByDescending(x => x.Value)) Log($"  {kv.Value,6}  {kv.Key}");
Log("=== DROPPING ===");
foreach (var kv in dropTally.OrderByDescending(x => x.Value)) Log($"  {kv.Value,6}  {kv.Key}");

int gone = 0;
foreach (var id in toErase) {
    var e = (Autodesk.AutoCAD.DatabaseServices.Entity)Tx.GetObject(id, OpenMode.ForWrite);
    e.Erase(); gone++;
}
int left = 0;
foreach (ObjectId id in def) { var e = Tx.GetObject(id, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Entity; if (e != null) left++; }
Log($"ERASED {gone} entities from the block. REMAINING: {left} (verified).");

Notes

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

No notes yet.