← Inbox

C3D-LAYERAUDIT · Layer audit vs HCWA standard (read-only) done

Every layer with entity/text counts + flags, to compare against the HCWA required layer list.

Script file
C3D-LAYERAUDIT.cs
Target
active document · model space
Author
claude
Approved
yes · claude (read-only)
Timeout
60s

C# payload

// READ-ONLY: full layer audit for HCWA as-built compliance.
// List every layer: name, on/frozen, color, lineweight, and entity count by broad type (so we can
// see what's on it and whether text is mixed onto feature layers).
using System;
using System.Linq;
using System.Collections.Generic;
using Autodesk.AutoCAD.DatabaseServices;

var db = Db;
using (var tr = db.TransactionManager.StartTransaction())
{
    // counts per layer
    var count = new Dictionary<string,int>(StringComparer.OrdinalIgnoreCase);
    var textCount = new Dictionary<string,int>(StringComparer.OrdinalIgnoreCase);
    var ms = (BlockTableRecord)tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForRead);
    foreach (ObjectId id in ms)
    {
        var e = tr.GetObject(id, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Entity;
        if (e == null) continue;
        count[e.Layer] = count.TryGetValue(e.Layer, out var c) ? c+1 : 1;
        if (e is DBText || e is MText) textCount[e.Layer] = textCount.TryGetValue(e.Layer, out var t) ? t+1 : 1;
    }

    var lt = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForRead);
    var rows = new List<string>();
    foreach (ObjectId id in lt)
    {
        var l = (LayerTableRecord)tr.GetObject(id, OpenMode.ForRead);
        int c = count.TryGetValue(l.Name, out var cc) ? cc : 0;
        int t = textCount.TryGetValue(l.Name, out var tt) ? tt : 0;
        rows.Add($"{l.Name} | ents={c} text={t} | {(l.IsFrozen?"FROZEN":"thawed")}{(l.IsOff?" OFF":"")} c={l.Color.ColorIndex}");
    }
    rows.Sort(StringComparer.OrdinalIgnoreCase);
    Log($"LAYERS ({rows.Count}):");
    foreach (var r in rows) Log("  " + r);
    tr.Commit();
}

Result

Status
success
Drawing file
C:\Users\sanja\OneDrive\_SurveyDisco\260613 - 5030 E Lake Pkwy, Stockbridge, GA 30281, USA\SS_Outfall_260612_SHEET.dwg
Message
Executed C3D-LAYERAUDIT (0 entities touched).
Entities
Duration
359 ms
Civil 3D
25.0.0.0

Log

LAYERS (22):
  0 | ents=117 text=0 | thawed c=7
  Defpoints | ents=0 text=0 | thawed c=7
  P-GRID | ents=15 text=0 | thawed c=8
  P-GRID-TEXT | ents=21 text=21 | thawed c=8
  P-GROUND | ents=2 text=0 | thawed c=42
  P-INTC | ents=1 text=0 | thawed c=7
  P-MHOL | ents=14 text=0 | thawed c=5
  P-PIPE | ents=1 text=0 | thawed c=1
  P-TEXT | ents=81 text=41 | thawed c=7
  SHEET | ents=0 text=0 | thawed c=7
  V-CREEK | ents=22 text=0 | FROZEN c=4
  V-CTRL | ents=1 text=1 | thawed c=6
  V-ESMT-SSE | ents=1 text=1 | thawed c=4
  V-GRID | ents=13 text=0 | FROZEN c=8
  V-GRID-TEXT | ents=13 text=13 | FROZEN c=8
  V-HIDE | ents=22 text=0 | FROZEN c=6
  V-PTS-OG | ents=28 text=0 | thawed c=2
  V-SSWR-MHOL | ents=0 text=0 | thawed c=5
  V-SSWR-PIPE | ents=1 text=0 | thawed c=1
  V-SSWR-TEXT | ents=21 text=21 | FROZEN c=7
  V-WTF | ents=36 text=0 | FROZEN c=6
  VIEWPORTS | ents=0 text=0 | thawed c=7

Notes

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

No notes yet.