4 Replies Latest reply on Jun 18, 2008 6:27 PM by Anna Wood

    Using a Macro to Change Drawing Fonts

    Kurt Gaetano
      Hi,

      I am trying to use Solidworks Macro Recorder to automate a seemingly simple task. I want to change the fonts used for all the options under "Tools/Options/Document Properties/Annotation Font". I've recorded the keystrokes/mouse movements to do this using the recorder. When I run it, nothing happens. If i use the macro editor to look at the macro, it's essentially empty.

      I'm obviously doing something fundamentally wrong, but I don't know what.

      Can the Macro Recorder access/change these options?

      Is there another/better way to do this?

      I have changed the drawing sheet templates & part templates to use the fonts I want, but we have hundreds of files saved with the old fonts. I need a method of mass updating them. I thought a macro woud be a good way to do this. I have to open many of them for other reasons, but don't want to have to do these changes manually if I can avoid it.

      Any suggestions or ideas?

      Thanks!
        • Using a Macro to Change Drawing Fonts
          Anna Wood
          Here is a macro I have used to update drawing fonts.

          -------------------------------------------------------------
          Option Explicit

          Dim swApp As SldWorks.SldWorks
          Dim swModel As SldWorks.ModelDoc2
          Dim swDraw As SldWorks.DrawingDoc

          Dim FontName As String
          Dim retval As Boolean

          Dim TextFormatObj As Object
          Dim swTextFormat As SldWorks.TextFormat

          Sub main()

          Set swApp = Application.SldWorks
          Set swModel = swApp.ActiveDoc
          Set swDraw = swModel

          FontName = "Century Gothic"

          retval = ReplaceFont(swDetailingBalloonTextFormat, FontName)
          retval = ReplaceFont(swDetailingDetailLabelTextFormat, FontName)
          retval = ReplaceFont(swDetailingDetailTextFormat, FontName)
          retval = ReplaceFont(swDetailingDimensionTextFormat, FontName)
          retval = ReplaceFont(swDetailingGeneralTableTextFormat, FontName)
          retval = ReplaceFont(swDetailingNoteTextFormat, FontName)
          retval = ReplaceFont(swDetailingSectionLabelTextFormat, FontName)
          retval = ReplaceFont(swDetailingSectionTextFormat, FontName)
          retval = ReplaceFont(swDetailingSurfaceFinishTextFormat, FontName)
          retval = ReplaceFont(swDetailingViewArrowTextFormat, FontName)
          retval = ReplaceFont(swDetailingWeldSymbolTextFormat, FontName)

          End Sub

          Function ReplaceFont(AName As swUserPreferenceTextFormat_e, Fname As String)
          Set TextFormatObj = swModel.GetUserPreferenceTextFormat(AName)
          Set swTextFormat = TextFormatObj
          swTextFormat.TypeFaceName = Fname
          ReplaceFont = swModel.SetUserPreferenceTextFormat(AName, swTextFormat)
          End Function
          ------------------------------------------------------------------------------------

          Cheers,
            • Using a Macro to Change Drawing Fonts
              Kurt Gaetano
              Anna,

              Thanks for the reply. A couple of points I failed to mention:

              1 This is for Solidworks 2008 SP 3.0
              2 I do know very little about VB or Solidworks API programming. I am just starting to teach myself something about VB programming (I downloaded the Visual Studio Express application from Microsoft yesterday), but I have just begun and at this point, I don't know how to put a program of this type together correctly. I tried to copy the text you sent into a new macro in solidworks macro editor. When running the debugger, it errored out. I have attached a few screen dumps of the error code & the debug window - I don't know if you will be able to see them in this post or not.

              It errored on the Function line "Set TextFormatObj = swModel.GetUserPreferenceTextFormat(AName)" with a "Run-Time error 91" (Object variable or With block variable not set).

              Thanks
              • Using a Macro to Change Drawing Fonts
                Kurt Gaetano
                Anna

                Please ignore my last post about the error. For whatever reason, it now seems to be working perfectly. I don't know what changed. The only thing I changed originally was the name of the font, but that was before when it was erroring out. I haven't changed anything since then, but I tried running it again and now it runs fine?!?!

                Thanks a million, you're an angel.