Below code shows the procedure to add a new text style to database. Also, the code makes the newly added text style as active/current text style by setting the database property “Database.Textstyle”
<CommandMethod("TestFont")> _
Public Shared Sub TestFont()
Dim doc As Document = _
Application.DocumentManager.MdiActiveDocument
Dim db As Database = _
doc.Database
Dim tm As Transaction = _
db.TransactionManager.StartTransaction()
Dim ed As Editor = doc.Editor
Using tm
Dim st As TextStyleTable = CType(tm.GetObject( _
db.TextStyleTableId, _
OpenMode.ForWrite, False), _
TextStyleTable)
Dim str As TextStyleTableRecord = _
New TextStyleTableRecord()
str.Name = "MyStyle"
st.Add(str)
'Following are properties to set by default,
'you can also modify them
'str.FileName = "txt.shx"
'str.PriorSize = 0.2
'str.ObliquingAngle = 0.0
'str.XScale = 1.0
'str.TextSize = 0.0
'str.IsVertical = False
'str.IsShapeFile = False
'using the font descriptor to set the new font style
'Imports Autodesk.AutoCAD.GraphicsInterface
str.Font = New FontDescriptor("Times New Roman", _
True, True, Nothing, Nothing)
tm.AddNewlyCreatedDBObject(str, True)
'make as current
db.Textstyle = str.ObjectId
tm.Commit()
End Using
End Sub
