Message 1 of 6
Retrieving Current TextStyle and Determine if ShapeFile (SHX) or Not
Not applicable
07-18-2009
07:01 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm developing an application that inserts mtext contents based on user input. I thought I'd go the extra mile and also allow the user to format the font from within my application. Just the basics, Bold, Italics, and Underline. There's a small caviat, text styles of the shape file type do not allow Bold or Italics, only underline. So in my application, I would like to capture the current textstyle and determine if it is a shape file or not so that I can disable these options when necessary. I've tried using the Filename property of the current database textstylerecord, but the extension (.shx) will only show up after the "Use Big Font" option has been manually selected at least once from the Text Style dialog (Style command).
For example, on an initial run the Filename property may read "txt" for a txt.shx font name. If I use the Style command, select "Use Big Font", select Apply, then deselect "Use Big Font" and reselect Apply, the Filename property displays "txt.shx". What is the "Use Big Font" option doing to force the extension to show? I'll need consistency for my application. Is there a better way of doing this from within the .Net environment?
Below is a quick and dirty illustration of where I'm going with the code. It's trying to display the filename for now until I can figure out how to get the extension to display consistently without user manual intervention.
'Initialize document & document editor objects
Dim dwgCurrent As ApplicationServices.Document = ApplicationServices.Application.DocumentManager.MdiActiveDocument
'Retrieve and return assigned FontType
Dim tmgFontType As DatabaseServices.TransactionManager = dwgCurrent.TransactionManager
Try
Using trnFontType As DatabaseServices.Transaction = tmgFontType.StartTransaction
Dim tstFontType As DatabaseServices.TextStyleTable = dwgCurrent.Database.TextStyleTableId.GetObject(DatabaseServices.OpenMode.ForRead)
Dim tsrFontType As DatabaseServices.TextStyleTableRecord = dwgCurrent.Database.Textstyle.GetObject(DatabaseServices.OpenMode.ForRead)
Dim strFontType As String = tsrFontType.FileName
'If Microsoft.VisualBasic.Strings.Right(tsrFontType.FileName, 4).ToUpper = ".SHX" Then
' btnBold.Enabled = False
' btnItalics.Enabled = False
'Else
' btnBold.Enabled = True
' btnItalics.Enabled = True
'End If
MsgBox(tsrFontType.FileName)
End Using
Catch exFontType As Autodesk.AutoCAD.Runtime.Exception
End Try
For example, on an initial run the Filename property may read "txt" for a txt.shx font name. If I use the Style command, select "Use Big Font", select Apply, then deselect "Use Big Font" and reselect Apply, the Filename property displays "txt.shx". What is the "Use Big Font" option doing to force the extension to show? I'll need consistency for my application. Is there a better way of doing this from within the .Net environment?
Below is a quick and dirty illustration of where I'm going with the code. It's trying to display the filename for now until I can figure out how to get the extension to display consistently without user manual intervention.
'Initialize document & document editor objects
Dim dwgCurrent As ApplicationServices.Document = ApplicationServices.Application.DocumentManager.MdiActiveDocument
'Retrieve and return assigned FontType
Dim tmgFontType As DatabaseServices.TransactionManager = dwgCurrent.TransactionManager
Try
Using trnFontType As DatabaseServices.Transaction = tmgFontType.StartTransaction
Dim tstFontType As DatabaseServices.TextStyleTable = dwgCurrent.Database.TextStyleTableId.GetObject(DatabaseServices.OpenMode.ForRead)
Dim tsrFontType As DatabaseServices.TextStyleTableRecord = dwgCurrent.Database.Textstyle.GetObject(DatabaseServices.OpenMode.ForRead)
Dim strFontType As String = tsrFontType.FileName
'If Microsoft.VisualBasic.Strings.Right(tsrFontType.FileName, 4).ToUpper = ".SHX" Then
' btnBold.Enabled = False
' btnItalics.Enabled = False
'Else
' btnBold.Enabled = True
' btnItalics.Enabled = True
'End If
MsgBox(tsrFontType.FileName)
End Using
Catch exFontType As Autodesk.AutoCAD.Runtime.Exception
End Try