← Inbox

C3D-0364 · READ-ONLY: full layer table + entity counts + PDF underlays [C3D-LAYREAD] error

Lists every layer with color, frozen/off state, description and model-space entity count; enumerates PDF underlay references with their source file and layer; and flags any layer whose name contains PDF. Needed before merging the pdf layers or reorganizing anything.

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

C# payload

// READ-ONLY. Full layer table + entity count per layer, plus any PDF underlays and their layers,
// so we can see what "the pdfx layers" are before merging anything.
Log("drawing: " + Db.Filename);

// count entities per layer across model space
var count = new Dictionary<string,int>();
var ms = (BlockTableRecord)Tx.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(Db), OpenMode.ForRead);
foreach (ObjectId id in ms) {
    var e = Tx.GetObject(id, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Entity;
    if (e == null) continue;
    if (!count.ContainsKey(e.Layer)) count[e.Layer]=0;
    count[e.Layer]++;
}

var lt = (LayerTable)Tx.GetObject(Db.LayerTableId, OpenMode.ForRead);
var names = new List<string>();
foreach (ObjectId id in lt) names.Add(((LayerTableRecord)Tx.GetObject(id, OpenMode.ForRead)).Name);
names.Sort(StringComparer.OrdinalIgnoreCase);

Log("=== LAYERS (" + names.Count + ") ===");
foreach (var n in names) {
    var l = (LayerTableRecord)Tx.GetObject(lt[n], OpenMode.ForRead);
    int c = count.ContainsKey(n) ? count[n] : 0;
    Log(string.Format("  {0,-34} color={1,-10} {2,-4}{3} ents={4}  desc=\"{5}\"",
        l.Name, l.Color.ColorNameForDisplay, l.IsFrozen?"FRZ ":"", l.IsOff?"OFF":"", c, l.Description ?? ""));
}

// PDF underlays
Log("");
Log("=== PDF UNDERLAYS ===");
int pdf=0;
foreach (ObjectId id in ms) {
    var u = Tx.GetObject(id, OpenMode.ForRead) as PdfReference;
    if (u == null) continue;
    pdf++;
    Autodesk.AutoCAD.DatabaseServices.Extents3d ex;
    try { ex = u.GeometricExtents; } catch { ex = new Autodesk.AutoCAD.DatabaseServices.Extents3d(); }
    string defName="";
    try { var def=(PdfDefinition)Tx.GetObject(u.DefinitionId, OpenMode.ForRead); defName=def.SourceFileName + " (page "+def.ActivePage+")"; } catch {}
    Log(string.Format("  [{0}] PdfReference on layer {1}  ({2:F1},{3:F1})-({4:F1},{5:F1})  src=\"{6}\"",
        u.Handle, u.Layer, ex.MinPoint.X, ex.MinPoint.Y, ex.MaxPoint.X, ex.MaxPoint.Y, defName));
}
if (pdf==0) Log("  none");

// any layer whose name looks pdf-ish
Log("");
Log("=== layers matching *PDF* ===");
foreach (var n in names) if (n.IndexOf("PDF",StringComparison.OrdinalIgnoreCase)>=0)
    Log("  " + n + "  ents=" + (count.ContainsKey(n)?count[n]:0));

Result

Status
error
Drawing file
C:\Users\sanja\OneDrive\_SurveyDisco\260613 - 5030 E Lake Pkwy, Stockbridge, GA 30281, USA\ACAD-260612-Springdale Sanitary Sewer Extension As-Built 60 wPROFILE.dwg
Message
Compile error: (39,125): error CS1061: 'PdfDefinition' does not contain a definition for 'ActivePage' and no accessible extension method 'ActivePage' accepting a first argument of type 'PdfDefinition' could be found (are you missing a using directive or an assembly reference?)
Entities
Duration
409 ms
Civil 3D
25.0.0.0

Notes

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

No notes yet.