← Inbox

C3D-0099 · READ-ONLY: PDF layers and entity counts in the active drawing [PDF-COUNT] done

Lists every layer whose name starts with PDF in the currently active drawing, with how many entities each holds and whether it is frozen, plus totals. No changes.

Script file
C3D-0099.cs
Target
active document · model space
Author
claude
Approved
yes · reviewer
Timeout
240s

C# payload

// READ-ONLY. How many PDF layers are in THIS drawing and how many entities do they hold?
// Nothing is modified.
var lt = (LayerTable)Tx.GetObject(Db.LayerTableId, OpenMode.ForRead);
var bt = (BlockTable)Tx.GetObject(Db.BlockTableId, OpenMode.ForRead);
Log("drawing: " + Db.Filename);

var counts = new Dictionary<string,int>();
int scanned = 0;
foreach (ObjectId btrId in bt) {
    var btr = (BlockTableRecord)Tx.GetObject(btrId, OpenMode.ForRead);
    foreach (ObjectId id in btr) {
        Autodesk.AutoCAD.DatabaseServices.DBObject o;
        try { o = Tx.GetObject(id, OpenMode.ForRead); } catch { continue; }
        var ent = o as Autodesk.AutoCAD.DatabaseServices.Entity;
        if (ent == null) continue;
        scanned++;
        string lay; try { lay = ent.Layer; } catch { continue; }
        if (!counts.ContainsKey(lay)) counts[lay] = 0;
        counts[lay]++;
    }
}

int nPdfLayers = 0, nPdfEnts = 0, nTotalLayers = 0;
foreach (ObjectId lid in lt) {
    var l = (LayerTableRecord)Tx.GetObject(lid, OpenMode.ForRead);
    nTotalLayers++;
    if (!l.Name.ToUpper().StartsWith("PDF")) continue;
    nPdfLayers++;
    int c = counts.ContainsKey(l.Name) ? counts[l.Name] : 0;
    nPdfEnts += c;
    Log(String.Format("  {0,-40} n={1}{2}", l.Name, c, l.IsFrozen ? "  FROZEN" : ""));
}
Log("");
Log("layers total=" + nTotalLayers + "   PDF layers=" + nPdfLayers + "   entities on them=" + nPdfEnts);
Log("entities scanned=" + scanned);

Result

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

Log

drawing: C:\Users\sanja\OneDrive\_SurveyDisco\260613 - 5030 E Lake Pkwy, Stockbridge, GA 30281, USA\ACAD-260612 - CSTORE WATER ABS 30.dwg
  PDF2_C-DEMO                              n=4
  PDF2_E GRAVEL                            n=427
  PDF2_V-BNDY-ANNO                         n=1
  PDF2_E IPF-SET                           n=10
  PDF2_INTER_CONTOURS                      n=5365
  PDF2_SWM                                 n=14
  PDF2_P-ESMT                              n=3

layers total=63   PDF layers=7   entities on them=5824
entities scanned=7013

Notes

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

No notes yet.