← Inbox

C3D-BLK-USEDLAYERS · Layers with objects done

Read-only: every layer that currently carries objects, with entity counts and types, across model space, all layouts and all block definitions.

Script file
C3D-BLK-USEDLAYERS.cs
Target
SS_BLOCK_22X17 · model space
Author
claude
Approved
yes · reviewer
Timeout
180s

C# payload

// READ-ONLY: which layers actually carry objects in THIS drawing, and what kind.
// Counts model space, every layout's paper space, and every block definition.
var lt = (LayerTable)Tx.GetObject(Db.LayerTableId, OpenMode.ForRead);
var used  = new Dictionary<string,int>();
var kinds = new Dictionary<string, Dictionary<string,int>>();

var bt = (BlockTable)Tx.GetObject(Db.BlockTableId, OpenMode.ForRead);
foreach (ObjectId bid in bt) {
    var btr = (BlockTableRecord)Tx.GetObject(bid, OpenMode.ForRead);
    foreach (ObjectId id in btr) {
        var e = Tx.GetObject(id, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Entity;
        if (e == null) continue;
        used[e.Layer] = used.ContainsKey(e.Layer) ? used[e.Layer]+1 : 1;
        if (!kinds.ContainsKey(e.Layer)) kinds[e.Layer] = new Dictionary<string,int>();
        var k = e.GetType().Name;
        kinds[e.Layer][k] = kinds[e.Layer].ContainsKey(k) ? kinds[e.Layer][k]+1 : 1;
    }
}

int total = 0;
foreach (ObjectId id in lt) total++;

var names = new List<string>(used.Keys);
names.Sort();
Log("### " + names.Count + " layers WITH objects (of " + total + " total)");
foreach (var n in names) {
    var parts = new List<string>();
    foreach (var kv in kinds[n]) parts.Add(kv.Value + " " + kv.Key);
    var ltr = lt.Has(n) ? (LayerTableRecord)Tx.GetObject(lt[n], OpenMode.ForRead) : null;
    var flags = ltr == null ? "" :
        (ltr.IsOff ? " OFF" : "") + (ltr.IsFrozen ? " FROZEN" : "") + (ltr.IsLocked ? " LOCKED" : "");
    Log(n + "|" + used[n] + "|" + string.Join(", ", parts) + "|" + flags);
}

Result

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

Log

### 53 layers WITH objects (of 323 total)
0|1374|570 CogoPoint, 15 ParcelSegmentLabel, 1 ParcelSegmentTable, 4 Viewport, 3 BlockReference, 613 Line, 31 Circle, 59 Polyline, 1 Leader, 16 DBText, 17 Arc, 2 Wipeout, 25 Hatch, 2 Solid, 3 Solid3d, 3 Ole2Frame, 4 MText, 5 AttributeDefinition|
A-BLDG|3|3 Line|
ANNOTATIONS|36|36 DBText| FROZEN
BLOCK_CLOSURE|62|14 DBText, 24 Line, 8 Polyline, 2 Arc, 8 Solid, 4 Polyline2d, 2 MText|
BLOCK_LEGEND|20|1 DBText, 1 MText, 5 BlockReference, 1 Circle, 12 Line|
BLOCK_NORTH_ARROW|303|270 Line, 24 Polyline2d, 3 DBText, 6 Arc|
BLOCK_NOTES_FLOOD|4|4 MText|
BLOCK_STAMP|144|4 Arc, 4 Circle, 112 DBText, 16 Line, 8 Polyline|
BLOCK_TB2|591|56 DBText, 479 Line, 8 MText, 6 Viewport, 2 BlockReference, 40 AttributeDefinition|
C-0-GNRL-NOTE-INDX|1|1 MText|
C-ANNO|20|4 MText, 1 GeneralSegmentLabel, 14 NoteLabel, 1 Solid|
C-ANNO-TABL-TTBL|6|6 Site|
C-PROP-LINE|1|1 ParcelSegment|
Defpoints|37|36 DBPoint, 1 Polyline|
FENCE-CHAIN|1|1 Line|
G-NOTE|114|2 DBText, 106 Line, 2 Arc, 2 Circle, 2 AttributeDefinition|
G-TTLB-HALF|5|3 DBText, 2 AttributeDefinition|
G-TTLB-LIGH|5|3 Line, 2 Polyline|
G-TTLB-THIN|1|1 Polyline|
G-TTLB-TTF|26|24 AttributeDefinition, 2 DBText|
LS-BOULDER|12|3 Hatch, 8 Polyline, 1 BlockReference|
LS-EX. TREE|150|2 BlockReference, 10 Circle, 2 Hatch, 1 Polyline, 55 Arc, 80 Line|
SEWER_EASEMENT|2|1 Site, 1 ParcelSegment|
SEWER_LINE|7|7 Line|
SPDETAIL|1|1 DBText|
SPDIMENSION|108|81 Line, 18 Solid, 9 DBText|
SPOVERVIEW|1|1 DBText|
SPPAINT|2093|2093 Line|
SPSHAPE_OUTLINE|79|79 Line|
SS-0-FRAME|1|1 Line| FROZEN
SS-BOUNDARY|6|1 MText, 2 BlockReference, 1 Arc, 2 Line|
SS-BOUNDARY ANGEL|40|8 Polyline, 9 DBText, 3 MText, 13 Line, 1 Arc, 4 Solid, 2 Polyline2d| FROZEN
SS-BOUNDARY BLUE|5|4 Line, 1 Arc|
SS-BOUNDARY CYAN|4|2 Line, 2 Polyline|
SS-BOUNDARY MAG|1|1 Arc|
SS-BOUNDARY_PTS|1|1 MText|
SS-BUFFER LANDSCAPE|2|2 Site|
SS-CL OF CREEK|1|1 Polyline|
SS-FLOW WELL|1|1 Circle|
SS-V-BLDG-OTLN|36|35 Line, 1 Polyline|
SS-V-BRKL-TOP|2|1 FeatureLine, 1 Line|
SS-V-ROAD-CURB|93|2 Site, 34 Line, 1 BlockReference, 1 Circle, 15 MText, 12 AlignedDimension, 2 Polyline, 2 RasterImage, 24 Solid|
SS-X-FENCE WOOD|6|2 Polyline, 4 Line|
TB1|10|10 Line|
TREES|1|1 DBText|
V-CTRL-HCPT|3|2 CogoPoint, 1 BlockReference|
V-NODE-STRM|2|2 BlockReference|
V-NODE-TREE|2|2 CogoPoint|
V-NODE-WATR|3|2 BlockReference, 1 Line|
WATER_LINE|1|1 Parcel|
www.cadblocksfree.com|23|1 Polyline, 2 Ole2Frame, 15 Line, 3 Arc, 2 BlockReference|
X-PROP-CRNR|1|1 Circle|
X-STRM-STRC|1|1 Polyline|

Notes

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

No notes yet.