Skip to content

Latest commit

 

History

History
75 lines (58 loc) · 2.08 KB

File metadata and controls

75 lines (58 loc) · 2.08 KB

TextStyleTable Class

Overview

The TextStyleTable class is a symbol table that contains all text style definitions in an AutoCAD drawing.

Namespace

Autodesk.AutoCAD.DatabaseServices

Inheritance Hierarchy

System.Object
  └─ RXObject
      └─ DBObject
          └─ SymbolTable
              └─ TextStyleTable

Key Methods

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)

Code Examples

Example 1: Listing All Text Styles

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();
}

Example 2: Creating a New Text Style

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();
}

Related Objects

  • Database - Contains TextStyleTableId
  • DBText - Uses text styles
  • MText - Uses text styles
  • TextStyleTableRecord - Text style definition

References