C3D-0048 · Layer filter: USED C- (8 layers) [FILTER-USED-C] done
Creates a layer group filter holding the 8 C- layers that actually contain entities (C-ANNO, C-ANNO-CERT, C-ANNO-CERT-LINE, C-ANNO-TABL-TTBL, C-PROP, C-PROP-LINE, C-PROP-LINE-TEXT, C-PROP-TABL). PDF2_C-* excluded. Replaces any existing filter of the same name and reads it back to verify.
C# payload
// Layer filter "USED C-": the C- layers that actually hold entities.
//
// Membership from the per-layer entity counts in C3D-0045 (used in model space or a layout):
// C-ANNO 3, C-ANNO-CERT 3, C-ANNO-CERT-LINE 9, C-ANNO-TABL-TTBL 5,
// C-PROP 3, C-PROP-LINE 4, C-PROP-LINE-TEXT 8, C-PROP-TABL 2
// PDF2_C-* are NOT included - those are PDF layers, excluded by the same rule as before.
//
// Same struct trap as the last filter: Db.LayerFilters is a copy and must be assigned back, and
// Autodesk.AutoCAD.LayerManager is not in ScriptRunner's imports so the types are fully qualified.
// Idempotent: replaces an existing filter of this name rather than stacking a duplicate.
string[] KEEP = new string[] {
"C-ANNO", "C-ANNO-CERT", "C-ANNO-CERT-LINE", "C-ANNO-TABL-TTBL",
"C-PROP", "C-PROP-LINE", "C-PROP-LINE-TEXT", "C-PROP-TABL",
};
const string FILTER_NAME = "USED C-";
var root = Db.LayerFilters;
var parent = root.Root;
Autodesk.AutoCAD.LayerManager.LayerFilter existing = null;
foreach (Autodesk.AutoCAD.LayerManager.LayerFilter f in parent.NestedFilters)
if (f.Name == FILTER_NAME) { existing = f; break; }
if (existing != null) { parent.NestedFilters.Remove(existing); Log("replaced existing filter"); }
var grp = new Autodesk.AutoCAD.LayerManager.LayerGroup();
grp.Name = FILTER_NAME;
var lt = (LayerTable)Tx.GetObject(Db.LayerTableId, OpenMode.ForRead);
int added = 0, missing = 0;
foreach (string nm in KEEP) {
if (!lt.Has(nm)) { Log(" MISSING layer: " + nm); missing++; continue; }
var l = (LayerTableRecord)Tx.GetObject(lt[nm], OpenMode.ForRead);
grp.LayerIds.Add(l.ObjectId);
added++;
}
parent.NestedFilters.Add(grp);
Db.LayerFilters = root;
int verified = -1;
var check = Db.LayerFilters;
foreach (Autodesk.AutoCAD.LayerManager.LayerFilter f in check.Root.NestedFilters)
if (f.Name == FILTER_NAME) verified = ((Autodesk.AutoCAD.LayerManager.LayerGroup)f).LayerIds.Count;
Log("filter \"" + FILTER_NAME + "\": added " + added + ", missing " + missing);
Log("read back from Db.LayerFilters: " + verified + " layers (verified)");
Ed.Regen();
Result
Log
filter "USED C-": added 8, missing 0 read back from Db.LayerFilters: 8 layers (verified)
Notes
What worked, what didn't, job-specific gotchas — flagged notes feed the recipes.
No notes yet.