Retrieving Current TextStyle and Determine if ShapeFile (SHX) or Not

Retrieving Current TextStyle and Determine if ShapeFile (SHX) or Not

Anonymous
Not applicable
1,220 Views
5 Replies
Message 1 of 6

Retrieving Current TextStyle and Determine if ShapeFile (SHX) or Not

Anonymous
Not applicable
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
0 Likes
1,221 Views
5 Replies
Replies (5)
Message 2 of 6

cadMeUp
Collaborator
Collaborator
For AutoCAD 2009, a TextStyleTableRecord has a get/set property that you can access 'IsShapeFile':
"This returns true when the text font file is interpreted as a shape record, otherwise it returns false when it is interpreted as a text record."

Maybe give that a try...
0 Likes
Message 3 of 6

Anonymous
Not applicable
Sorry for the late reply, I've been working on another project that's intense enough to keep me away from this for a couple days.

I tried this property before and it gives me a False value regardless of the setting (Again, I'm changing the setting via the Style command). It is showing false if a *.ttf is selected and if a *.shx is selected. Is there a prerequisite to using this property?
0 Likes
Message 4 of 6

cadMeUp
Collaborator
Collaborator
I tried your code in AutoCAD 2009 and it shows the file ext everytime, no need to set "Use Big Font" at all. Which version of AutoCAD are you developing this for?

Maybe you can try this and see what prints at the command line:

{code}
Dim ed As Editor = dwgCurrent.Editor
Dim strFontType As String = tsrFontType.FileName
Dim fInfo As System.IO.FileInfo = New System.IO.FileInfo(strFontType)
Dim ext As String = fInfo.Extension.ToLower()

ed.WriteMessage(vbCrLf + "Name: " + fInfo.FullName)
ed.WriteMessage(vbCrLf + "Ext: " + ext)

If ext.Contains("shx") Then
ed.WriteMessage(vbCrLf + "IS SHX!")
Else
ed.WriteMessage(vbCrLf + "NOT SHX!")
End If
{code}
0 Likes
Message 5 of 6

Anonymous
Not applicable
Interesting.... I'm running AutoCAD 2008. I tried your code and it's in the same boat as the other, it only works after I do the "Use Big Font" thing. It's almost as though a change needs to be made in order for it to show the full name. I did figure a funny work around. It turns out that the TypeFace value for the font object is only populated if it is a TrueTextFont type. So it's probably not the most clear and preferred approach, but seems to work. Using your code, I incorporated the concept for illustration.

Dim fntFontType As New GraphicsInterface.FontDescriptor
fntFontType = tsrFontType.Font

Dim ed As Editor = dwgCurrent.Editor

If fntFontType.TypeFace.Trim = "" Then
ed.WriteMessage(vbCrLf + "IS SHX!")
Else
ed.WriteMessage(vbCrLf + "NOT SHX!")
End If

I think I may try the original code on someone else's machine and see if that produces good results. I'm now beginning to wonder about the install on my machine. It's either that, our menu setup, or maybe there is a difference in how it works between 2008 and 2009.
0 Likes
Message 6 of 6

Anonymous
Not applicable
Well, I began digging a little deeper since it worked on your machine. I think I've narrowed the fact down to the Shapefile being used. We use a custom shape file ETEXT.shx which is saved to the default template as the default font. If I change the template to start with an AutoCAD provided shape file, the original code works. The ETEXT.shx is really old and created before I came to this organization to control how certain characters are displayed, I wonder if it needs to be recreated.
0 Likes