I'm finding examples everywhere that seem to work for others, but the following code is not working for me. It completes with no errors, but when I check with the STYLE command, there is no TextStyle added.
/// <source> http://through-the-interface.typepad.com/through_the_interface/2011/07/minesweeper-in-autocad-using-net.html </source>
/// <summary> adds a text style to a drawing if it doesn't already exist </summary>
public static void AddTextStyle()
{
Database db = HostApplicationServices.WorkingDatabase;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
TextStyleTable tab = (TextStyleTable)trans.GetObject(db.TextStyleTableId, OpenMode.ForWrite, false);
if (!tab.Has("MinesweeperStyle"))
{
TextStyleTableRecord rec = new TextStyleTableRecord();
rec.Name = "MinesweeperStyle";
rec.FileName = "txt.shx";
//rec.Font = new Autodesk.AutoCAD.GraphicsInterface.FontDescriptor("txt", false, false, 0, 0);
rec.IsShapeFile = true;
rec.TextSize = 1.0;
rec.XScale = 1.0;
/* MessageBox.Show(string.Format("Name: {0}\nBigFontFileName: {1}\nFileName: {2}\nFont: {3}\nIsShapeFile: {4}\nIsVertical: {5}\n" +
"ObliquingAngle: {6}\nTextSize: {7}\nXScale: {8}", rec.Name, rec.BigFontFileName, rec.FileName, rec.Font.ToString(),
rec.IsShapeFile.ToString(), rec.IsVertical.ToString(), rec.ObliquingAngle.ToString(), rec.TextSize.ToString(), rec.XScale.ToString()),
"Create TextStyle"); */
tab.Add(rec);
trans.AddNewlyCreatedDBObject(rec, true);
}
trans.Commit();
}
}
Anybody know what I'm missing?