.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to add new textstyle?

2 REPLIES 2
Reply
Message 1 of 3
Anonymous
715 Views, 2 Replies

How to add new textstyle?

Hello
I would like to add a new textstyle.
But, it does not work.
Thanks

'--------------------------------------------------------------------------
TextStyleAdd("WELDCNT", "SAS_____.pfb", "SAS_____.pfb")

Private Sub TextStyleAdd(ByVal StyleName As String, ByVal FontFileName As String, ByVal FontName As String)

Dim textStyleTableRecordId As ObjectId
Dim TextStyleTableRecord As TextStyleTableRecord = New TextStyleTableRecord

TextStyleTableRecord.Name = StyleName

'Error in this line----------------------------------------------------
TextStyleTableRecord.Font = New Autodesk.AutoCAD.GraphicsInterface.FontDescriptor(StyleName, True, False, 0, 34)
'----------------------------------------------------------------------
TextStyleTableRecord.FileName = FontFileName
TextStyleTableRecord.FlagBits = 0
TextStyleTableRecord.IsShapeFile = False
TextStyleTableRecord.IsVertical = False
TextStyleTableRecord.ObliquingAngle = 0.0
TextStyleTableRecord.PriorSize = 3.0
TextStyleTableRecord.TextSize = 3.0
TextStyleTableRecord.XScale = 0.8

Dim TextStyleTable As TextStyleTable = Trans.GetObject(DB.TextStyleTableId, OpenMode.ForWrite)
textStyleTableRecordId = TextStyleTable.Add(TextStyleTableRecord)
Trans.AddNewlyCreatedDBObject(TextStyleTableRecord, True)

End Sub
2 REPLIES 2
Message 2 of 3
ReneRam
in reply to: Anonymous

I use the following with no proplems:

Sub AddTextStyle(ByVal TextStyleName As String, ByVal FontName As String)
Dim myDWG As ApplicationServices.Document
Dim myDB As DatabaseServices.Database
Dim myTransMan As DatabaseServices.TransactionManager
Dim myTrans As DatabaseServices.Transaction

myDWG = ApplicationServices.Application.DocumentManager.MdiActiveDocument
myDB = myDWG.Database
myTransMan = myDWG.TransactionManager
myTrans = myTransMan.StartTransaction

Dim myTST As DatabaseServices.TextStyleTable
Dim myTSTR As DatabaseServices.TextStyleTableRecord

Try
myTST = myDB.TextStyleTableId.GetObject(DatabaseServices.OpenMode.ForWrite)
myTSTR = New DatabaseServices.TextStyleTableRecord
myTSTR.Name = TextStyleName
Dim myFont As New GraphicsInterface.FontDescriptor(FontName, False, False, 0, 0)
myTSTR.Font = myFont
myTST.Add(myTSTR)
myTrans.AddNewlyCreatedDBObject(myTSTR, True)
Catch ex As Exception
If ex.Message = "eDuplicateRecordName" Then
' style is already present
myTrans.Dispose()
myTransMan.Dispose()
Exit Sub
End If
End Try
' Commit and Dispose Transaction
myTrans.Commit() : myTrans.Dispose() : myTransMan.Dispose()

End Sub

Hope it helps
René
Message 3 of 3
Anonymous
in reply to: Anonymous

Thanks for your help.
It works fine.

Thanks again

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost