5 Replies Latest reply on Jan 4, 2017 10:16 AM by William Cruz

    Macro to set the Measure tool options, can't get it done

    Craig Sink

      I'm attempting to create a macro that will set the options in the measure tool. It appears that the IMeasure interface is what I want to use, but it's not doing anything. Below is my code:

       

      Option Explicit
      Dim swApp As SldWorks.SldWorks
      Dim swModel As SldWorks.ModelDoc2
      Dim swModelDocExt As SldWorks.ModelDocExtension
      Dim swMeasure As SldWorks.Measure
      Dim Places As Integer
      Sub main()
          Set swApp = Application.SldWorks
          Set swModel = swApp.ActiveDoc
          Set swModelDocExt = swModel.Extension
          Set swMeasure = swModelDocExt.CreateMeasure
          
          Places = 8
          MsgBox ("swMeasure Original value:" & swMeasure.AngleDecimalPlaces)
          swMeasure.AngleDecimalPlaces = Places
          swMeasure.LengthDecimalPlaces = Places
          MsgBox ("swMeasure new value:" & swMeasure.AngleDecimalPlaces)
          
      End Sub
      

       

      As you can see, I display the value before and after. The value always starts as 8, no matter if I've ran the macro before or not. And the places on the angle units are set to 3 currently.

       

      It appears that I don't have the correct interface? Thanks for any and all assistance!

        • Re: Macro to set the Measure tool options, can't get it done
          Scott Stuart

          Could it be because it's set to document settings? Maybe you need to set it to custom settings first.

          Capture.PNG

          • Re: Macro to set the Measure tool options, can't get it done
            Steven Barry

            Try opening the measure tool and see if it is set to "Use document settings" or not.  I can't seem to find an API command or property that controls that radio button, but it might be worth confirming it is set to "Use Custom Settings" before running your code.

             

            • Re: Macro to set the Measure tool options, can't get it done
              Josh Brady

              I don't think setting the Measure tool options is in the IMeasure interface.  All that does is get you programmatic access to the same functionality/data that a user can get through the UI. 

              • Re: Macro to set the Measure tool options, can't get it done
                Nilesh Patel

                Hi Craig,

                I have modified your macro slightly. I have added 'IModelDocExtension.SetUserPrefernceInteger' method to change document level units.

                 

                Option Explicit
                Dim swApp As SldWorks.SldWorks
                Dim swModel As SldWorks.ModelDoc2
                Dim swModelDocExt As SldWorks.ModelDocExtension
                Dim swMeasure As SldWorks.Measure
                Dim Places As Integer
                
                
                Sub main()
                    Set swApp = Application.SldWorks
                    Set swModel = swApp.ActiveDoc
                    Set swModelDocExt = swModel.Extension
                    Set swMeasure = swModelDocExt.CreateMeasure
                    
                    Debug.Print swModelDocExt.GetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsAngularDecimalPlaces, swUserPreferenceOption_e.swDetailingNoOptionSpecified)
                    Debug.Print swModelDocExt.GetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsLinearDecimalPlaces, swUserPreferenceOption_e.swDetailingNoOptionSpecified)
                    
                    Places = 5
                    Debug.Print "swMeasure Original value: " & swMeasure.LengthDecimalPlaces
                    
                    Debug.Print swModelDocExt.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsAngularDecimalPlaces, swUserPreferenceOption_e.swDetailingNoOptionSpecified, Places)
                    Debug.Print swModelDocExt.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsLinearDecimalPlaces, swUserPreferenceOption_e.swDetailingNoOptionSpecified, Places)
                    
                    swMeasure.AngleDecimalPlaces = Places
                    swMeasure.LengthDecimalPlaces = Places
                    
                    Debug.Print "swMeasure New value: " & swMeasure.LengthDecimalPlaces
                      
                End Sub
                

                 

                If you leave the measure tool option to 'Use document settings' and run the macro, you will see the decimal values change in measure tool option. 'Debug.Print "swMeasure New value: " & swMeasure.LengthDecimalPlaces' always prints the value set by 'Places' but for some reason 'Debug.Print "swMeasure Original value: " & swMeasure.LengthDecimalPlaces' always prints value of '8'. 'IModelDocExtension.GetUserPrefernceInteger' works OK too. Not sure why?

                 

                I cannot find API calls to toggle between 'Use document settings' and 'Use custom settings'.

                 

                Regards,

                • Re: Macro to set the Measure tool options, can't get it done
                  William Cruz

                  Set the ModelDoc units before making your call. See the following link.

                   

                  2016 SOLIDWORKS API Help - SetUnits Method (IModelDoc2)