← Inbox

C3D-0583 · Find what uses the A- layers done

Read-only: list entities in block definitions, attributes and viewport freeze lists that reference A-* layers.

Script file
C3D-0583.cs
Target
261001 - 5040 Rolling Rock Dr.dwg · model space
Author
claude
Approved
yes · auto-auth
Timeout
60s

C# payload

var lt=(LayerTable)Tx.GetObject(Db.LayerTableId,OpenMode.ForRead);
var aIds=new Dictionary<ObjectId,string>();
foreach(ObjectId id in lt){ var lr=(LayerTableRecord)Tx.GetObject(id,OpenMode.ForRead); if(lr.Name.StartsWith("A-",StringComparison.OrdinalIgnoreCase)) aIds[id]=lr.Name; }
var hits=new SortedDictionary<string,SortedDictionary<string,int>>();
Action<string,string> add=(l,w)=>{ if(!hits.ContainsKey(l)) hits[l]=new SortedDictionary<string,int>(); hits[l][w]=hits[l].ContainsKey(w)?hits[l][w]+1:1; };
var bt=(BlockTable)Tx.GetObject(Db.BlockTableId,OpenMode.ForRead);
foreach(ObjectId sid in bt){
  var b=(BlockTableRecord)Tx.GetObject(sid,OpenMode.ForRead);
  foreach(ObjectId id in b){
    var en=Tx.GetObject(id,OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Entity; if(en==null) continue;
    if(aIds.ContainsKey(en.LayerId)) add(aIds[en.LayerId], (b.IsLayout?"TOP "+b.Name:"in block '"+b.Name+"'")+" "+en.GetType().Name);
    var br=en as BlockReference;
    if(br!=null) foreach(ObjectId aid in br.AttributeCollection){ var ar=(AttributeReference)Tx.GetObject(aid,OpenMode.ForRead); if(aIds.ContainsKey(ar.LayerId)) add(aIds[ar.LayerId],"attribute "+ar.Tag+" on insert of '"+br.Name+"' in "+b.Name); }
    var vp=en as Viewport;
    if(vp!=null){ foreach(ObjectId fid in vp.GetFrozenLayers()) if(aIds.ContainsKey(fid)) add(aIds[fid],"VP-frozen in viewport h="+vp.Handle+" ("+b.Name+")"); }
  }
}
foreach(var kv in aIds) if(!hits.ContainsKey(kv.Value)) add(kv.Value,"no entity/attribute/viewport reference found");
foreach(var kv in hits){ Log("=== "+kv.Key); foreach(var w in kv.Value) Log("   "+w.Key+"  x"+w.Value); }

Result

Status
success
Drawing file
C:\Users\sanja\OneDrive\_SurveyDisco\261001 - 5040 Rolling Rock Dr, Sugar Hill, GA 30518, USA\261001 - 5040 Rolling Rock Dr.dwg
Message
Executed C3D-0583 (0 entities touched).
Entities
—
Duration
663 ms
Civil 3D
25.0.0.0

Log

=== A-BLDG
   no entity/attribute/viewport reference found  x1
=== A-BLDG-FPRT
   no entity/attribute/viewport reference found  x1
=== A-BLDG-SITE
   no entity/attribute/viewport reference found  x1
=== A-BLDG-UTIL
   no entity/attribute/viewport reference found  x1
=== A-PROP-LINE
   no entity/attribute/viewport reference found  x1

Notes

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

No notes yet.