We need to iterate through the text style symbol table of the current database from time to time. Here is some succinct and good code in C# to do so.
[CommandMethod("TextStyleIterator")]
public static void TextStyleIterator_Method()
{
Database database = HostApplicationServices.WorkingDatabase;
using (Transaction transaction = database.TransactionManager.StartTransaction())
{
SymbolTable symTable = (SymbolTable)transaction.GetObject(database.TextStyleTableId, OpenMode.ForRead);
foreach (ObjectId id in symTable)
{
TextStyleTableRecord symbol = (TextStyleTableRecord)transaction.GetObject(id, OpenMode.ForRead);
//TODO: Access to the symbol
MgdAcApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage(string.Format("\nName: {0}", symbol.Name));
}
transaction.Commit();
}
}
If the command is run, something like the following may be printed out to the command line window.
Command: TextStyleIterator
Name: STANDARD
Name: SANSSERIFBOLD
Name: ROMANS-115
Name: ROMANS-80
Name: ROMANC
Name: ROMAND
Name: SANSERIF
……
The leading edge AutoCAD .NET Addin Wizard (AcadNetAddinWizard) provides various wizards, coders, and widgets to help program AutoCAD addins in C#, VB.NET or even C++/CLI.
Hi Spider when I use your above code I only seem to have two TextStyleTableRecord entires: Standard and Annotative - I do not have all the different font styles that you do. any ideas?
Posted by: BKSpurgeon | 11/08/2017 at 04:13 AM
Hi BKSpurgeon, it might be the DWG you tried the code with was too new. By default, new drawings only have the two text styles as mentioned. The DWG we tried on our end was a bit old and complex.
Posted by: Spiderinnet1 | 11/08/2017 at 06:23 PM
yes Mr Spider you are right i used an old cad file and it worked with other font styles.
rgds
Ben
Posted by: BKSpurgeon | 11/08/2017 at 09:14 PM
Ben, glad to know it works fine now.
Posted by: Spiderinnet1 | 11/09/2017 at 02:04 AM
Check your public ip address onlie Visit My Ip Address
Posted by: DJ | 08/20/2019 at 04:12 AM