PDA

View Full Version : Help modifying a text style



sgroff
2006-10-02, 01:20 PM
I wrote a routine to change the fontfile of existing text styles in a drawing. It turns out that a while ago, some one decided to create what became a standard linetype w/ text in it. When the text styles font gets changed to arial, it messes up the line type.
here is the routine i have so far


Sub Wingding()
Dim oTextStyle As AcadTextStyle
For Each oTextStyle In ThisDrawing.TextStyles
If UCase(oTextStyle.Name) Like "*wetland" Then
oTextStyle.fontFile = "c:\windows\fonts\wingding.ttf"
End If
Next oTextStyle
ThisDrawing.Regen acAllViewports
End Sub

[ Moderator Action = ON ] What are [ CODE ] tags... (http://forums.augi.com/misc.php?do=bbcode#code) [ Moderator Action = OFF ]

I want to find the text style "wetland" ( if it exist in the drawing) and change the fontfile from Arial to wingding.ttf.

I need help figuring out why the above code doesnt work. any suggestions?

sgroff
2006-10-02, 02:00 PM
thanks for the Code tag, Opie.. my bad.

rkmcswain
2006-10-02, 05:17 PM
I need help figuring out why the above code doesnt work. any suggestions?

Either add Option Compare Text to your module -or- change the compare string to upper case.

Currently you are comparing the UPPER CASE style name to a lower case string (*wetland)

MikeJarosz
2006-10-02, 05:56 PM
Either add Option Compare Text to your module -or- change the compare string to upper case.

Currently you are comparing the UPPER CASE style name to a lower case string (*wetland)I always counsel ACAD users to get out of the habit of ignoring case. 99% of the Acad users I deal with work with their caps lock on. And email and IM don't help cure bad habits either. I always force case in VBA before doing a comparison ESPECIALLY if it comes from user input.

I was once told that early Acad (before Windows!) used 7 bit ASCII, which is caps only and no special characters. That's why you had to use those stupid %% tricks to get degrees or other special characters.

sgroff
2006-10-03, 03:21 AM
Either add Option Compare Text to your module -or- change the compare string to upper case.

Currently you are comparing the UPPER CASE style name to a lower case string (*wetland)


works great. thanks
I also found i could use Lcase.

sgroff
2006-10-03, 04:14 AM
Sub Wingding()
Dim oTextStyle As AcadTextStyle
Dim currTextStyle As AcadTextStyle
Set currTextStyle = ThisDrawing.ActiveTextStyle
For Each oTextStyle In ThisDrawing.TextStyles
If LCase(oTextStyle.Name) Like "*wetland" Then
oTextStyle.fontFile = "c:\windows\fonts\wingding.ttf"
End If
Next oTextStyle
ThisDrawing.ActiveTextStyle = currTextStyle
ThisDrawing.Regen acAllViewports
MsgBox "The MUNBD linetype has been repaired ", vbInformation, "ActiveTextStyle Example"
End Sub

on that last line, what is this for? , vbInformation, "ActiveTextStyle Example"
I took it out and ran the program & the only diffrence i'm noticing is the sound when the msgbox pops up.

Here is the final program. Seeing how i'm very green when it comes to VBA, any suggestions are always welcome. thanks in advance.


Option Explicit

Sub Wingding()
Dim oTextStyle As AcadTextStyle
Dim currTextStyle As AcadTextStyle
'remembers the current Text Style.
Set currTextStyle = ThisDrawing.ActiveTextStyle
'Finds the wetland text style and changes the font back to wingdings
For Each oTextStyle In ThisDrawing.TextStyles
If LCase(oTextStyle.Name) Like "*wetland" Then
oTextStyle.fontFile = "c:\windows\fonts\wingding.ttf"
'pops up a personalized message box confiriming the repair.
MsgBox "The MUNBD linetype has been repaired for " & Environ("UserName"), vbInformation, "ActiveTextStyle Example"
End If
Next oTextStyle
'restores the previous text style to current.
ThisDrawing.ActiveTextStyle = currTextStyle
'regens the drawing so changes can be seen.
ThisDrawing.Regen acAllViewports
End Sub