C3D-FILTER-NONC · Layer filter: all except C-* done
Creates a layer filter group "All except C-" containing every layer whose name does not start with C-. Replaces an existing group of the same name; verifies by reading the filter tree back off the database.
C# payload
// Layer filter holding every layer EXCEPT the C-* ones (the AIA/NCS C-PROP, C-ROAD, C-TOPO,
// C-ANNO ... family that came in with the template and is mostly unused here).
// LayerGroup carries explicit layer ids, so membership is fixed at build time.
// Autodesk.AutoCAD.LayerManager is NOT in the host's imports - fully qualified below.
// Db.LayerFilters is a STRUCT: the edited tree must be assigned back or nothing persists
// (cookbook 16). Replaces an existing group of the same name so this is re-runnable.
// Host owns Tx; host regens after commit.
const string GROUP = "All except C-";
var lt = (LayerTable)Tx.GetObject(Db.LayerTableId, OpenMode.ForRead);
var keep = new List<ObjectId>();
int skipped = 0, total = 0;
foreach (ObjectId id in lt)
{
var l = (LayerTableRecord)Tx.GetObject(id, OpenMode.ForRead);
total++;
if (l.Name.StartsWith("C-", System.StringComparison.OrdinalIgnoreCase)) { skipped++; continue; }
keep.Add(id);
}
Log(total + " layers: " + keep.Count + " kept, " + skipped + " skipped (C-*)");
var tree = Db.LayerFilters;
var root = tree.Root;
Autodesk.AutoCAD.LayerManager.LayerFilter dup = null;
foreach (Autodesk.AutoCAD.LayerManager.LayerFilter f in root.NestedFilters)
if (f.Name == GROUP) { dup = f; break; }
if (dup != null) { root.NestedFilters.Remove(dup); Log("removed existing '" + GROUP + "'"); }
var grp = new Autodesk.AutoCAD.LayerManager.LayerGroup();
grp.Name = GROUP;
foreach (var id in keep) grp.LayerIds.Add(id);
root.NestedFilters.Add(grp);
Db.LayerFilters = tree;
int found = -1;
foreach (Autodesk.AutoCAD.LayerManager.LayerFilter f in Db.LayerFilters.Root.NestedFilters)
if (f.Name == GROUP)
{
var g2 = f as Autodesk.AutoCAD.LayerManager.LayerGroup;
found = (g2 == null) ? -2 : g2.LayerIds.Count;
}
Log("filter '" + GROUP + "' read back from the database: " +
(found >= 0 ? found + " layer(s) (verified)" : found == -2 ? "not a LayerGroup" : "NOT FOUND"));
Result
Log
401 layers: 218 kept, 183 skipped (C-*) filter 'All except C-' read back from the database: 218 layer(s) (verified)
Notes
What worked, what didn't, job-specific gotchas — flagged notes feed the recipes.
No notes yet.