← Inbox

C3D-0625 · Read B/L lines, labels, viewports (read-only) error

Read-only: SS-BUFFER SETBACK line coordinates, the text inside every Note/Segment label (exploded in memory, nothing appended), every viewport's paper/model mapping, text styles, layers and linetypes - to place the R9 notes, labels, creek CL and 75' buffer.

Script file
C3D-0625.cs
Target
260714 - 285 Huckaby Rd 22x17.dwg · model space
Author
claude
Approved
yes · auto-auth
Timeout
60s

C# payload

var bt=(BlockTable)Tx.GetObject(Db.BlockTableId,OpenMode.ForRead);
var ms=(BlockTableRecord)Tx.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(Db),OpenMode.ForRead);
foreach(ObjectId id in ms){
  var en=Tx.GetObject(id,OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Entity; if(en==null) continue;
  if(en.Layer=="SS-BUFFER SETBACK" && en is Line){ var l=(Line)en; Log("BL|"+l.Handle+"|"+l.StartPoint.X.ToString("F2")+","+l.StartPoint.Y.ToString("F2")+"|"+l.EndPoint.X.ToString("F2")+","+l.EndPoint.Y.ToString("F2")); }
  if(en.GetType().Name=="NoteLabel"||en.GetType().Name.Contains("SegmentLabel")){
    try{ var col=new DBObjectCollection(); en.Explode(col); var parts=new List<string>(); Point3d? at=null;
      foreach(DBObject o in col){ if(o is MText){ parts.Add(((MText)o).Text); at=at??((MText)o).Location; } else if(o is DBText){ parts.Add(((DBText)o).TextString); at=at??((DBText)o).Position; } else if(o is BlockReference){ var c2=new DBObjectCollection(); ((BlockReference)o).Explode(c2); foreach(DBObject o2 in c2){ if(o2 is MText){ parts.Add(((MText)o2).Text); at=at??((MText)o2).Location;} else if(o2 is DBText){ parts.Add(((DBText)o2).TextString); at=at??((DBText)o2).Position;} o2.Dispose(); } } o.Dispose(); }
      Log("LBL|"+en.GetType().Name+"|"+en.Handle+"|"+en.Layer+"|"+(at.HasValue?at.Value.X.ToString("F1")+","+at.Value.Y.ToString("F1"):"")+"|"+string.Join(" / ",parts).Replace("\n"," ")); }catch(System.Exception ex){ Log("LBL|"+en.Handle+"|explode failed "+ex.Message); } }
}
foreach(ObjectId sid in bt){ var b=(BlockTableRecord)Tx.GetObject(sid,OpenMode.ForRead); if(!b.IsLayout) continue; var lo=(Layout)Tx.GetObject(b.LayoutId,OpenMode.ForRead);
  foreach(ObjectId id in b){ var vp=Tx.GetObject(id,OpenMode.ForRead) as Viewport; if(vp==null) continue;
    Log("VP|"+lo.LayoutName+"|"+vp.Handle+"|num="+vp.Number+"|layer="+vp.Layer+"|c="+vp.CenterPoint.X.ToString("F4")+","+vp.CenterPoint.Y.ToString("F4")+"|w="+vp.Width.ToString("F4")+"|h="+vp.Height.ToString("F4")+"|viewCenter="+vp.ViewCenter.X.ToString("F3")+","+vp.ViewCenter.Y.ToString("F3")+"|target="+vp.ViewTarget.X.ToString("F3")+","+vp.ViewTarget.Y.ToString("F3")+"|scale="+vp.CustomScale.ToString("F8")+"|twist="+(vp.TwistAngle*180/Math.PI).ToString("F4")+"|dir="+vp.ViewDirection); } }
var tst=(TextStyleTable)Tx.GetObject(Db.TextStyleTableId,OpenMode.ForRead); var ns=new List<string>(); foreach(ObjectId id in tst){ var r=(TextStyleTableRecord)Tx.GetObject(id,OpenMode.ForRead); ns.Add(r.Name+"("+r.FileName+")"); } Log("STYLES|"+string.Join(", ",ns));
Log("CURSTYLE|"+((TextStyleTableRecord)Tx.GetObject(Db.Textstyle,OpenMode.ForRead)).Name);
var lt=(LayerTable)Tx.GetObject(Db.LayerTableId,OpenMode.ForRead); var ln=new List<string>(); foreach(ObjectId id in lt){ var r=(LayerTableRecord)Tx.GetObject(id,OpenMode.ForRead); ln.Add(r.Name+(r.IsFrozen?"[F]":"")+(r.IsOff?"[OFF]":"")); } Log("LAYERS|"+string.Join(", ",ln));
var ltt=(LinetypeTable)Tx.GetObject(Db.LinetypeTableId,OpenMode.ForRead); var lts=new List<string>(); foreach(ObjectId id in ltt){ lts.Add(((LinetypeTableRecord)Tx.GetObject(id,OpenMode.ForRead)).Name); } Log("LTYPES|"+string.Join(", ",lts));

Result

Status
error
Drawing file
C:\Users\sanja\OneDrive\_SurveyDisco\260714 - 285 Huckaby Rd, Brooks, GA 30205, USA\260714 - 285 Huckaby Rd 22x17.dwg
Message
Compile error: (8,15): error CS0104: 'DBObject' is an ambiguous reference between 'Autodesk.AutoCAD.DatabaseServices.DBObject' and 'Autodesk.Civil.DatabaseServices.DBObject'; (8,301): error CS0104: 'DBObject' is an ambiguous reference between 'Autodesk.AutoCAD.DatabaseServices.DBObject' and 'Autodesk.Civil.DatabaseServices.DBObject'
Entities
—
Duration
543 ms
Civil 3D
25.0.0.0

Notes

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

No notes yet.