← Inbox

C3D-0448 · Tally parcel label layers + viewport numbers (read-only) error

Count model-space Civil label entities by type and layer, and list real viewport numbers on the 11X17 layout.

Script file
C3D-0448.cs
Target
260711 - 281 Maranatha Trail.dwg · model space
Author
claude
Approved
yes · auto-auth
Timeout
60s

C# payload


var nameById=new System.Collections.Generic.Dictionary<ObjectId,string>();
var lt=(LayerTable)Tx.GetObject(Db.LayerTableId,OpenMode.ForRead);
foreach (ObjectId id in lt){ var lr=(LayerTableRecord)Tx.GetObject(id,OpenMode.ForRead); nameById[id]=lr.Name; }

// collect all parcel label entities in model space, tally their layers
var ms=(BlockTableRecord)Tx.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(Db),OpenMode.ForRead);
var tally=new System.Collections.Generic.Dictionary<string,int>();
int labels=0;
foreach(ObjectId eid in ms){
  var ent=Tx.GetObject(eid,OpenMode.ForRead) as Entity;
  if(ent==null) continue;
  string tn=ent.GetType().Name;
  if(tn.IndexOf("Label",StringComparison.OrdinalIgnoreCase)>=0){
    labels++;
    string key=tn+" @ "+ent.Layer;
    if(!tally.ContainsKey(key)) tally[key]=0; tally[key]++;
  }
}
Log("model-space label entities: "+labels);
foreach(var kv in tally) Log("  "+kv.Key+"  x"+kv.Value);

// real viewport numbers + frozen label-bearing layers
var lm=(DBDictionary)Tx.GetObject(Db.LayoutDictionaryId,OpenMode.ForRead);
foreach (System.Collections.DictionaryEntry de in lm){
  string lname=(string)de.Key;
  if(!lname.ToUpper().Contains("11X17")) continue;
  var lay=(Layout)Tx.GetObject((ObjectId)de.Value,OpenMode.ForRead);
  var btr=(BlockTableRecord)Tx.GetObject(lay.BlockTableRecordId,OpenMode.ForRead);
  int vpi=0;
  foreach (ObjectId eid in btr){
    var vp=Tx.GetObject(eid,OpenMode.ForRead) as Viewport;
    if(vp==null) continue;
    vpi++;
    Log("VP index "+vpi+" number="+vp.Number+" on="+vp.On+" clipped="+(vp.NonRectClipEntityId!=ObjectId.Null));
  }
}

Result

Status
error
Drawing file
C:\Users\sanja\OneDrive\_SurveyDisco\260711 - 281 Maranatha Trail, Lawrenceville, GA 30045, USA\260711 - 281 Maranatha Trail R2.dwg
Message
Compile error: (11,49): error CS0104: 'Entity' is an ambiguous reference between 'Autodesk.AutoCAD.DatabaseServices.Entity' and 'Autodesk.Civil.DatabaseServices.Entity'
Entities
Duration
374 ms
Civil 3D
25.0.0.0

Notes

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

No notes yet.