Results 1 to 6 of 6

Thread: Help modifying a text style

  1. #1
    100 Club sgroff's Avatar
    Join Date
    2006-07
    Location
    The Group "W" Bench
    Posts
    107
    Login to Give a bone
    0

    Default Help modifying a text style

    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

    Code:
    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... [ 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?
    Last edited by Opie; 2006-10-02 at 01:27 PM. Reason: [CODE] tags added, see moderator comment

  2. #2
    100 Club sgroff's Avatar
    Join Date
    2006-07
    Location
    The Group "W" Bench
    Posts
    107
    Login to Give a bone
    0

    Default Re: Help modifying a text style

    thanks for the Code tag, Opie.. my bad.

  3. #3
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,805
    Login to Give a bone
    0

    Default Re: Help modifying a text style

    Quote Originally Posted by sgroff
    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)
    R.K. McSwain | CAD Panacea |

  4. #4
    AUGI Addict MikeJarosz's Avatar
    Join Date
    2015-10
    Location
    New York NY
    Posts
    1,497
    Login to Give a bone
    0

    Default Re: Help modifying a text style

    Quote Originally Posted by rkmcswain
    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.

  5. #5
    100 Club sgroff's Avatar
    Join Date
    2006-07
    Location
    The Group "W" Bench
    Posts
    107
    Login to Give a bone
    0

    Default Re: Help modifying a text style

    Quote Originally Posted by rkmcswain
    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.
    Last edited by sgroff; 2006-10-03 at 03:23 AM.

  6. #6
    100 Club sgroff's Avatar
    Join Date
    2006-07
    Location
    The Group "W" Bench
    Posts
    107
    Login to Give a bone
    0

    Default Re: Help modifying a text style

    Code:
    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.
    Code:
    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
    Last edited by sgroff; 2006-10-03 at 06:15 AM.

Similar Threads

  1. Add Parametric Functions for Modifying Text in Families
    By Wish List System in forum Revit Architecture - Wish List
    Replies: 0
    Last Post: 2012-11-13, 02:55 PM
  2. Modifying the label style/ dragged state/ Leader/ line weight
    By eraska in forum AutoCAD Civil 3D - General
    Replies: 9
    Last Post: 2012-05-22, 02:13 PM
  3. Replies: 0
    Last Post: 2011-10-04, 11:21 PM
  4. Modifying Default Label Text
    By gtakayama in forum Revit Architecture - General
    Replies: 3
    Last Post: 2011-04-01, 03:46 PM
  5. Modifying Attribute Text - Change to upper-case
    By stephan.villeneuve in forum AutoCAD General
    Replies: 2
    Last Post: 2005-08-24, 02:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •