4 Replies Latest reply on Oct 1, 2016 6:30 PM by Yong Ning

    How to  set Annotations Font Options  in document proptities with API

    Yong Ning

      0.jpg

       

      Hope help ,With API  set  specify the default font for various types of annotations (Note, Dimension, Detail, Section, View Arrow, Surface Finish, Weld Symbol, Tables, and Balloon).

        • Re: How to  set Annotations Font Options  with API
          Deepak Gupta

          Check Annotation::SetTextFormat in API help

            • Re: How to  set Annotations Font Options  with API
              Yong Ning

              No SetText , I need set Annotation  in document proptities. .

               

               

              Sub main()

                  Dim swApp                       As SldWorks.SldWorks

                  Dim swModel                     As SldWorks.ModelDoc2

                  Dim swSelMgr                    As SldWorks.SelectionMgr

                  Dim swAnnObj                    As Object

                  Dim swAnn                       As SldWorks.Annotation

                  Dim swTextFormat                As SldWorks.TextFormat

                  Dim i                           As Long

                  Dim bRet                        As Boolean

                  Set swApp = Application.SldWorks

                  Set swModel = swApp.ActiveDoc

                  Set swSelMgr = swModel.SelectionManager

                  Set swAnnObj = swSelMgr.GetSelectedObject6(1, -1)

                  Set swAnn = swAnnObj.GetAnnotation

                  'Get text format information

                  Debug.Print "File = " & swModel.GetPathName

                  Debug.Print "  " & swAnn.GetName & " <" & swAnn.GetType & ">"

                  For i = 0 To swAnn.GetTextFormatCount - 1

                      Set swTextFormat = swAnn.GetTextFormat(i)

                      'Change text to be 10mm, bold, italic, and Comic Sans MS font

                      swTextFormat.CharHeight = 0.01

                      swTextFormat.Bold = True

                      swTextFormat.Italic = True

                      swTextFormat.TypeFaceName = "Comic Sans MS"

                      bRet = swAnn.SetTextFormat(i, False, swTextFormat)

                  Next

              End Sub

                • Re: How to  set Annotations Font Options  with API
                  Deepak Gupta

                  Are you using an older version (preferably older than 2010 as interface has changed).

                   

                  Check if you've these codes available IModelDocExtension::SetUserPreferenceTextFormat

                   

                  2010 SOLIDWORKS API Help - Document Properties > Annotations > Notes

                    • Re: How to  set Annotations Font Options  in document proptities with API
                      Yong Ning

                      Thank your tips.

                      the code is

                      ''

                      Private Sub test()

                         Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

                             Set SwApp = Application.SldWorks

                             Set SwModel = SwApp.ActiveDoc

                         Dim SwTextFormat As TextFormat

                             Set SwTextFormat = SwModel.GetUserPreferenceTextFormat(swDetailingDimensionTextFormat)

                             With SwTextFormat

                                 Debug.Print .CharHeight

                                 .CharHeight = 0.003

                             End With

                             SwModel.SetUserPreferenceTextFormat swDetailingDimensionTextFormat, SwTextFormat

                           

                      End Sub

                       

                      ************************************************************************************************************

                       

                      DP_Annotations-Notes.gif

                      2010 SOLIDWORKS API Help - Get and Set User Preferences Example (VBA)  http://help.solidworks.com/2010/english/api/sldworksapi/get_and_set_user_preferences_example_vb.htm

                       

                       

                          'Font...

                       

                       

                              Set TextFormatObj = ModelDocExtension.GetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingBalloonTextFormat, 0)

                              Set swTextFormat = TextFormatObj     

                              swTextFormat.Italic = True

                              swTextFormat.Bold = True    

                              boolstatus = ModelDocExtension.SetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingBalloonTextFormat, 0, swTextFormat)

                       

                      Enumeration

                      Comment

                      swDetailingBalloonTextFormat

                      Text font information used for BOM balloons.

                      swDetailingDetailTextFormat

                      Text font information used for the labels on the detail circles, but not the labels on detail views.

                      swDetailingDimensionTextFormat

                      Text font information used for dimensions.

                      swDetailingGeneralTableTextFormat

                      Text font information for general-table text.

                      swDetailingNoteTextFormat

                      Text font information used for notes, including the labels for detail views and section views.

                      swDetailingSectionTextFormat

                      Text font information used for the labels on section lines, but not the labels on section views.

                      swDetailingSurfaceFinishTextFormat

                      Text font information used for surface-finish symbol text.

                      swDetailingWeldSymbolTextFormat

                      Text font information for weld symbol text.