← Inbox

C3D-PDFSTRIP2 · Strip PDF block to HCWA-required layers done

DESTRUCTIVE - erases ~6,500 entities from inside the PDF block definition (contours, grading, title block, hatch patterns). Keeps sewer/water/hydrant/easement/boundary/road/building/annotation per the HCWA CAD Layers table. RECOMMEND running C3D-PDFLAYERS2 first and reviewing the list.

Script file
C3D-PDFSTRIP2.cs
Target
active document · model space
Author
claude
Approved
yes · reviewer
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).");

Result

Status
success
Drawing file
C:\Users\sanja\OneDrive\_SurveyDisco\260613 - 5030 E Lake Pkwy, Stockbridge, GA 30281, USA\CSTORE WATER ABS-260612_SHEET.dwg
Message
Executed C3D-PDFSTRIP2 (0 entities touched).
Entities
Duration
723 ms
Civil 3D
25.0.0.0

Log

=== KEEPING ===
     477  PDF_C-SIDEWLK-HTC
     324  PDF_V-BNDY-ANNO
     246  PDF_C-CURB-FACE
     238  PDF_V-ROAD-CURB
     200  PDF_Text
     137  PDF_V-WATR
     126  PDF_C-STRIPES
     120  PDF_C-BLDG-COLS
     100  PDF_C-SSWR-PIPE
      73  PDF_0-PIPE-SS-A-T
      61  PDF_V-ROAD-MRKG
      45  PDF_C-WATR-CNTR
      33  PDF_C-SSWR-LATS
      30  PDF_0-PIPE-SS-A
      29  PDF_C-WATR-ANNO
      25  PDF_C-STRM-CNTR
      18  PDF_V-STRM-GRAT
      17  PDF_E STORM TEXT
      16  PDF_C-WATR-STRC
      16  PDF_V-SSWR
      13  PDF_V-STRM-STRC-TEXT
      13  PDF_C-ANNO
      10  PDF_C-ESMT-BLDG-SBAK
       8  PDF_ESMT v2
       8  PDF_V-SSWR-ANNO
       7  PDF_V-BNDY
       7  PDF_E STORM
       7  PDF_C-WATR-TEXT
       6  PDF_C-SIDEWALKS
       3  PDF_V-ESMT
       2  PDF_GENERAL-TEXT
       1  PDF_P-RW
       1  PDF_P-ESMT
=== DROPPING ===
    5365  PDF_INTER_CONTOURS
    1152  PDF_INDEX_CONTOURS
     427  PDF_E GRAVEL
     408  PDF_PGRADE
     280  PDF_V-POWR-OVHD
     228  PDF_ae_title-36x24$TBORDER
      93  PDF_ae_title-36x24$T-BD-COPY
      69  PDF_GRAPHIC_SCALE
      61  PDF_C-SSWR-PIPE-PATT
      59  PDF_ae_title-36x24$SEAL2
      42  PDF_0-PIPE-STM C
      41  PDF_V-RIVR-EDGE
      32  PDF_0-PIPE-STM B
      32  PDF_0-PIPE-STM A
      31  PDF_0-ALIGN-SDL2-T
      30  PDF_E IPF-SET
      30  PDF_ae_title-36x24$TITLE
      27  PDF_ae_title-36x24$T-BD-INFO2
      24  PDF_C-SSWR-STRC-PATT
      23  PDF_E POWER
      21  PDF_ae_title-36x24$SEAL
      19  PDF_ae_title-36x24$T-BD-PROJ2
      15  PDF_C-CONC
      14  PDF_SWM
      12  PDF_ae_title-36x24$T-BD-PROJ
      12  PDF_ae_title-36x24$T-BD-LOGO
       5  PDF_E FENCE
       4  PDF_C-SIGNS
       3  PDF_2015_Flood_Map_DFIRM
       3  PDF_ae_title-36x24$T-BD-LINE
       3  PDF_ae_title-36x24$T-BD-INFO1
       3  PDF_REVISIONS
       2  PDF_E CONCRETE
       2  PDF_E WALL
       2  PDF_E EDGE PVMT
       2  PDF_Level 3
       1  PDF_P-Setbacks
       1  PDF_NOTES
       1  PDF_0-PIPE-EX SS
ERASED 8579 entities from the block. REMAINING: 2417 (verified).

Notes

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

No notes yet.