The TextStyleTable class is a symbol table that contains all text style definitions in an AutoCAD drawing.
Autodesk.AutoCAD.DatabaseServices
System.Object
└─ RXObject
└─ DBObject
└─ SymbolTable
└─ TextStyleTable
| Method | Return Type | Description |
|---|---|---|
Has(string) |
bool |
Checks if a text style exists by name |
this[string] |
ObjectId |
Gets text style ObjectId by name (indexer) |
using (Transaction tr = db.TransactionManager.StartTransaction())
{
TextStyleTable tst = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
ed.WriteMessage("\nText styles in drawing:");
foreach (ObjectId styleId in tst)
{
TextStyleTableRecord tstr = tr.GetObject(styleId, OpenMode.ForRead) as TextStyleTableRecord;
ed.WriteMessage($"\n {tstr.Name}");
ed.WriteMessage($" - Font: {tstr.FileName}");
}
tr.Commit();
}using (Transaction tr = db.TransactionManager.StartTransaction())
{
TextStyleTable tst = tr.GetObject(db.TextStyleTableId, OpenMode.ForWrite) as TextStyleTable;
if (!tst.Has("MyStyle"))
{
TextStyleTableRecord tstr = new TextStyleTableRecord();
tstr.Name = "MyStyle";
tstr.FileName = "arial.ttf";
tstr.TextSize = 0.0; // Variable height
tst.Add(tstr);
tr.AddNewlyCreatedDBObject(tstr, true);
}
tr.Commit();
}