5 Replies Latest reply on Sep 18, 2018 1:45 AM by Nishihama Sayuri

    How to change leader option using API (from Radius to Diameter)

    Nishihama Sayuri

      I drew a radius dimension in Part file.

      But I want to change this [Radius dimension]  to [Diameter dimension].

       

      I found this switch button in property manager.

      but I don't know the way to change options using API (VBA / VB.net).

      Can I change this options by API?

       

       

      thanks.

        • Re: How to change leader option using API (from Radius to Diameter)
          Marcos Rodríguez

          Hi Nishihama,

           

          I had the same problem, and I did a macro to change that and also more things.

           

          Try this piece of code, or download my macro from:

           

          Open Leaders on Diameter Dimensions

           

           

           

          Sub main()

          Set swApp = Application.SldWorks
          Set swModel = swApp.ActiveDoc
          If swModel Is Nothing Then
              MsgBox "No document loaded.", vbCritical
              End
          ElseIf swModel.GetType <> 3 Then
              MsgBox "Active Document is not a drawing", vbCritical
              End
          Else
              Set swDraw = swModel
          End If

          'First set Document properties for new dimensions
          Set swModelDocExtension = swModel.Extension

          swModelDocExtension.SetUserPreferenceToggle swDetailingRadialDimsDisplayWithSolidLeader, swDetailingDiameterDimension, False
          swModelDocExtension.SetUserPreferenceToggle swDetailingRadialDimsDisplayWithSolidLeader, swDetailingHoleDimension, False
          swModelDocExtension.SetUserPreferenceToggle swDetailingRadialDimsDisplayWithSolidLeader, swDetailingRadiusDimension, False

            • Re: How to change leader option using API (from Radius to Diameter)
              Nishihama Sayuri

              Hi Marcos,

              Thank you for your reply.

               

              Document Property has this parameters!  I see.

               

              I'll try it.

              I'll come back soon.

               

              thanks.

                • Re: How to change leader option using API (from Radius to Diameter)
                  Marcos Rodríguez

                  Hi Nishihama,

                   

                  I didn't read very well your post before answering it.

                   

                  Your issue is in the part environment, down the sketch level and my macro is for drawings and change different settings.

                   

                  You'll be worthy taking a look a these methods of either ModelDoc or ModelDocExtension:

                   

                  Good luck!

                    • Re: How to change leader option using API (from Radius to Diameter)
                      Nishihama Sayuri

                      Hi, Marcos

                       

                      thank you for your more help.

                      Yes, I want to draw dimensions in PART file.

                      Method [AddRadialDimension2 / AddDiameterDimension2] seems to be good for me.

                       

                      ---

                      I run your code in DRAW file, and  I found switch property.

                      Its name is [.Diametric].

                          swDispDim.Diametric = True     ' ■ Radial→Diameter

                          'swDispDim.Diametric = False   ' ■ Diameter→Radial

                       

                      ***

                      Dim swApp As Object
                      Dim swModel As ModelDoc2

                      Sub main()
                         
                          '---------------------------------------
                          ' Get Document
                          '---------------------------------------
                          Set swApp = Application.SldWorks
                          Set swModel = swApp.ActiveDoc
                          If swModel Is Nothing Then
                              MsgBox "No document loaded.", vbCritical
                              End
                          ElseIf swModel.GetType <> 3 Then
                              MsgBox "Active Document is not a drawing", vbCritical
                              End
                          Else
                              Set swDraw = swModel
                          End If
                         
                          'First set Document properties for new dimensions
                          Set swModelDocExtension = swModel.Extension

                      '    swModelDocExtension.SetUserPreferenceToggle swDetailingRadialDimsDisplayWithSolidLeader, swDetailingDiameterDimension, False
                      '    swModelDocExtension.SetUserPreferenceToggle swDetailingRadialDimsDisplayWithSolidLeader, swDetailingHoleDimension, False
                      '    swModelDocExtension.SetUserPreferenceToggle swDetailingRadialDimsDisplayWithSolidLeader, swDetailingRadiusDimension, False

                          '---------------------------------------
                          ' Select Radial/Diameter Dimension
                          '---------------------------------------
                          Dim swDispDim As DisplayDimension
                          Dim swSelMgr As SelectionMgr
                          Set swSelMgr = swModel.SelectionManager
                         
                          Set swDispDim = swSelMgr.GetSelectedObject5(1)
                         
                          swDispDim.Diametric = True     ' ■ Radial→Diameter
                          'swDispDim.Diametric = False   ' ■ Diameter→Radial
                                
                          swModel.EditRebuild3
                            
                          '---------------------------------------
                          ' Change Leader Type
                          '---------------------------------------
                          swDispDim.SetBrokenLeader2 False, swDisplayDimensionLeaderText_e.swBrokenLeaderAlignedText
                          swModel.EditRebuild3
                         
                          swDispDim.SetBrokenLeader2 False, swDisplayDimensionLeaderText_e.swBrokenLeaderHorizontalText
                          swModel.EditRebuild3
                         
                          swDispDim.SetBrokenLeader2 False, swDisplayDimensionLeaderText_e.swSolidLeaderAlignedText
                          swModel.EditRebuild3
                         
                          swDispDim.SetBrokenLeader2 False, swDisplayDimensionLeaderText_e.swSolidLeaderHorizontalText
                          swModel.EditRebuild3

                      End Sub