← Inbox

C3D-0585 · Find what uses the A- layers (styles/settings) rejected

Read-only: scan every non-entity object (Civil styles, settings, xrecords) for references to A-* layers.

Script file
C3D-0585.cs
Target
261001 - 5040 Rolling Rock Dr.dwg · model space
Author
claude
Approved
no
Timeout
60s

C# payload

var lt=(LayerTable)Tx.GetObject(Db.LayerTableId,OpenMode.ForRead);
var aIds=new Dictionary<ObjectId,string>(); var aNames=new HashSet<string>(StringComparer.OrdinalIgnoreCase);
foreach(ObjectId id in lt){ var lr=(LayerTableRecord)Tx.GetObject(id,OpenMode.ForRead); if(lr.Name.StartsWith("A-",StringComparison.OrdinalIgnoreCase)){ aIds[id]=lr.Name; aNames.Add(lr.Name);} }
var hits=new List<string>();
long seed=Db.Handseed.Value; int scanned=0;
var flags=System.Reflection.BindingFlags.Public|System.Reflection.BindingFlags.Instance;
for(long h=1; h<seed; h++){
  ObjectId oid;
  if(!Db.TryGetObjectId(new Handle(h), out oid) || oid.IsNull || oid.IsErased) continue;
  Autodesk.AutoCAD.DatabaseServices.DBObject o=null;
  try{ o=Tx.GetObject(oid,OpenMode.ForRead,false,true); }catch{ continue; }
  if(o==null || o is LayerTableRecord) continue;
  scanned++;
  string desc=null;
  try{ var np=o.GetType().GetProperty("Name"); if(np!=null) desc=np.GetValue(o) as string; }catch{}
  string who=o.GetType().Name+" '"+desc+"' h="+o.Handle;
  if(o is Autodesk.AutoCAD.DatabaseServices.Entity) continue;
  foreach(var m in o.GetType().GetMethods(flags)){
    if(!m.Name.StartsWith("GetDisplayStyle")) continue;
    var ps=m.GetParameters(); if(ps.Length!=1 || !ps[0].ParameterType.IsEnum) continue;
    foreach(var ev in Enum.GetValues(ps[0].ParameterType)){
      try{ var ds=m.Invoke(o,new object[]{ev}); if(ds==null) continue; var lp=ds.GetType().GetProperty("Layer"); var ln=lp==null?null:lp.GetValue(ds) as string;
        if(ln!=null && aNames.Contains(ln)) hits.Add(ln+"  <- "+who+"  "+m.Name+"("+ev+")"); }catch{}
    }
  }
  foreach(var p in o.GetType().GetProperties(flags)){
    if(p.GetIndexParameters().Length>0) continue;
    if(p.PropertyType!=typeof(ObjectId) && p.PropertyType!=typeof(string)) continue;
    object v=null; try{ v=p.GetValue(o); }catch{ continue; }
    if(v is ObjectId && aIds.ContainsKey((ObjectId)v)) hits.Add(aIds[(ObjectId)v]+"  <- "+who+"  ."+p.Name);
    else if(v is string && aNames.Contains((string)v)) hits.Add((string)v+"  <- "+who+"  ."+p.Name);
  }
  var xr=o as Xrecord;
  if(xr!=null && xr.Data!=null) foreach(TypedValue tv in xr.Data){ if(tv.Value is ObjectId && aIds.ContainsKey((ObjectId)tv.Value)) hits.Add(aIds[(ObjectId)tv.Value]+"  <- Xrecord h="+xr.Handle+" owner h="+xr.OwnerId.Handle); else if(tv.Value is string && aNames.Contains((string)tv.Value)) hits.Add((string)tv.Value+"  <- Xrecord(text) h="+xr.Handle+" owner h="+xr.OwnerId.Handle); }
}
Log("scanned non-entity objects: "+scanned);
foreach(var s in hits.Distinct().OrderBy(x=>x)) Log("  "+s);
Log("hits="+hits.Distinct().Count());

Notes

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

No notes yet.