11 Replies Latest reply on Dec 21, 2016 11:35 AM by Arif Akbas

    Change Dimension Text Size on a Drawing

    Checkcheck Master

      Hi there,

       

      I'm trying to change the dimension text size for a drawing with, in first instance, a recorded macro who looks like: See below.

       

      When I run the macro the font size didn't change on the drawing however when I check the document properties the size is changed in the value given in the macro.

      Rebuilding the document won't make any changes.

      The code looks fine to me and the API help describes the same procedure.

       

      What do I need to change to take effect ?

       

      Anyone ?

       

      Greetings !

       

      --------------------------------------------------------------------------------

      Dim swApp As Object

       

      Dim Part As Object

      Dim boolstatus As Boolean

      Dim longstatus As Long, longwarnings As Long

       

      Sub main()

       

      Set swApp = Application.SldWorks

       

      Set Part = swApp.ActiveDoc

      Dim myTextFormat As Object

      Set myTextFormat = Part.Extension.GetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingDimensionTextFormat, swUserPreferenceOption_e.swDetailingDimension)

      myTextFormat.CharHeightInPts = 16

      boolstatus = Part.Extension.SetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingDimensionTextFormat, swUserPreferenceOption_e.swDetailingDimension, myTextFormat)

      End Sub

      --------------------------------------------------------------------------------

        • Re: Change Dimension Text Size on a Drawing
          Oleg Bezyaev

          It's simple:

          Option Explicit

           

          Sub main()

           

              Dim swApp                       As SldWorks.SldWorks

              Dim swModel                     As SldWorks.ModelDoc2

              Dim swSelMgr                    As SldWorks.SelectionMgr

              Dim swDispDim                    As SldWorks.DisplayDimension

              Dim swTextFormat                As SldWorks.TextFormat

              Dim bRet                        As Boolean

                 

              Set swApp = Application.SldWorks

              Set swModel = swApp.ActiveDoc

              Set swSelMgr = swModel.SelectionManager

              Set swDispDim = swSelMgr.GetSelectedObject5(1)

              Set swTextFormat = swDispDim.GetTextFormat

             

                  swTextFormat.CharHeight = 0.13

                  swTextFormat.Bold = True

                  swTextFormat.Italic = True

                  swTextFormat.TypeFaceName = "Comic Sans MS"

                 

          bRet = swDispDim.SetTextFormat(0, swTextFormat)

          End Sub

            • Re: Change Dimension Text Size on a Drawing
              Checkcheck Master

              Thanks Oleg, I'm gonna try.

               

               

              Kind regards !

                • Re: Change Dimension Text Size on a Drawing
                  Checkcheck Master

                  Oleg,

                   

                  Tried your code, works nice when you have preselected a dimension, thanks again.

                   

                  You know how to do this for the whole document or sheet ?

                   

                   

                  Greetings !

                    • Re: Change Dimension Text Size on a Drawing
                      Deepak Gupta

                      For some reason the codes you're using (those are OK though), changes the overall font height but not for individual linear, radius, chamfer, etc.. And that is why the dimensions on the drawing doesn't update.

                       

                      But if you manually change the font height for overall dimensions, it does update all below it i.e for linear, radius, chamfer, etc.

                      • Re: Change Dimension Text Size on a Drawing
                        Oleg Bezyaev

                        Option Explicit

                         

                        Sub main()

                         

                            Dim swApp                       As SldWorks.SldWorks

                            Dim swModel                    As SldWorks.ModelDoc2

                            Dim swDraw                      As SldWorks.DrawingDoc

                            Dim swView                      As SldWorks.View

                            Dim swDispDim                 As SldWorks.DisplayDimension

                            Dim swTextFormat             As SldWorks.TextFormat

                            Dim bRet                          As Boolean

                           

                            Set swApp = Application.SldWorks

                            Set swModel = swApp.ActiveDoc

                            Set swDraw = swModel

                         

                         

                            Set swView = swDraw.GetFirstView

                         

                         

                            Do While Not swView Is Nothing

                         

                         

                                Set swDispDim = swView.GetFirstDisplayDimension5

                               

                                Do While Not swDispDim Is Nothing

                                    Set swTextFormat = swDispDim.GetTextFormat

                          

                                swTextFormat.CharHeight = 0.06

                                swTextFormat.Bold = True

                                swTextFormat.Italic = True

                                swTextFormat.TypeFaceName = "Comic Sans MS"

                              

                                    bRet = swDispDim.SetTextFormat(0, swTextFormat)

                         

                         

                                    Set swDispDim = swDispDim.GetNext3

                                Loop

                                Set swView = swView.GetNextView

                            Loop

                        End Sub

                        If my answer is right, check "Correct Answer"

                  • Re: Change Dimension Text Size on a Drawing
                    Amirtharaj Vk

                    Hi!!

                     

                    You have to set fond size for all type of dimensions while using API. I have shown sample below to change font  for linear and angular dimensions.

                     

                    ''-----------------------------------

                    Dim swApp As SldWorks.SldWorks

                    Dim Part As SldWorks.ModelDoc2

                    Dim myTextFormat As SldWorks.TextFormat

                    Dim font_size As Integer

                    Dim boolstatus As Boolean

                    Dim longstatus As Long, longwarnings As Long

                     

                    Sub main()

                     

                    Set swApp = Application.SldWorks

                    Set Part = swApp.ActiveDoc

                    font_size = 16

                     

                    ''-- Overall Dimension Font

                    Set myTextFormat = Part.Extension.GetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingDimensionTextFormat, swUserPreferenceOption_e.swDetailingDimension)

                    myTextFormat.CharHeightInPts = font_size

                    boolstatus = Part.Extension.SetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingDimensionTextFormat, swUserPreferenceOption_e.swDetailingDimension, _

                    myTextFormat)

                    ''-- Linear Dimension Font

                    Set myTextFormat = Part.Extension.GetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingDimensionTextFormat, swUserPreferenceOption_e.swDetailingLinearDimension)

                    myTextFormat.CharHeightInPts = font_size

                    boolstatus = Part.Extension.SetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingDimensionTextFormat, swUserPreferenceOption_e.swDetailingLinearDimension, _

                    myTextFormat)

                    ''-- Angular Dimension Font

                    Set myTextFormat = Part.Extension.GetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingDimensionTextFormat, swUserPreferenceOption_e.swDetailingAngleDimension)

                    myTextFormat.CharHeightInPts = font_size

                    boolstatus = Part.Extension.SetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingDimensionTextFormat, swUserPreferenceOption_e.swDetailingAngleDimension, _

                    myTextFormat)

                     

                    Part.ForceRebuild3 (True)

                    End Sub

                     

                    ''-----------------------------------

                     

                    Regards

                    V K Amirtharaj

                    EGS Computers India Pvt Ltd

                    Dassault System SolidWorks Reseller

                    Chennai | Tamilnadu | India

                    http://www.egsindia.com/solidworks.html