5 Replies Latest reply on Aug 17, 2018 3:55 AM by Deepak Gupta

    Unit name for volume - swDmUnitsMassPropVolume_e

    Niels Raahauge

      'Hi - Can anybody help me getting parameters from swDmUnitsMassPropVolume_e like this exsample

      'BR Niels

       

      ' This code returns units name for Angle and Length

       

      Dim swApp As SldWorks.SldWorks

      Dim Part As SldWorks.ModelDoc2

      Dim docUserUnitAngle As SldWorks.UserUnit

      Dim docUserUnitLength As SldWorks.UserUnit

      Dim boolstatus As Boolean

      Dim ModelDocExtension As SldWorks.ModelDocExtension

       

      Option Explicit

       

      Sub main()

       

          Set swApp = Application.SldWorks

          Set Part = swApp.ActiveDoc

          Set ModelDocExtension = Part.Extension

          Set docUserUnitAngle = Part.GetUserUnit(swAngleUnit)

          Set docUserUnitLength = Part.GetUserUnit(swLengthUnit)

       

          Debug.Print "  Full units name: " & docUserUnitAngle.GetFullUnitName(True)

          Debug.Print "  Full units name: " & docUserUnitLength.GetFullUnitName(True)

       

      End Sub

        • Re: Unit name for volume - swDmUnitsMassPropVolume_e
          Deepak Gupta

          Under API help, look for following method:

           

          IModelDocExtension::GetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropVolume,zswUserPreferenceOption_e.swDetailingNoOptionSpecified)

            • Re: Unit name for volume - swDmUnitsMassPropVolume_e
              Niels Raahauge

              'Thank you for a quick answer.

              'I still can't get it working -

              'I use same symtax but Part.GetUserUnit(swUnitsMassPropVolume) return Nothing -  Compiler message : missing a variabel set. 'Why? (I tried the same before I send the question)

               

              ' This code returns units name for Angle, Length, (Volume-not working)

               

              Dim swApp As SldWorks.SldWorks

              Dim Part As SldWorks.ModelDoc2

               

              Dim docUserUnitAngle As SldWorks.UserUnit

              Dim docUserUnitLength As SldWorks.UserUnit

              Dim docUserUnitVolume As SldWorks.UserUnit

               

              Dim boolstatus As Boolean

              Dim ModelDocExtension As SldWorks.ModelDocExtension

               

              Option Explicit

               

              Sub main()

               

                  Set swApp = Application.SldWorks

                  Set Part = swApp.ActiveDoc

                  Set ModelDocExtension = Part.Extension

                 

                  Set docUserUnitAngle = Part.GetUserUnit(swAngleUnit)

                  Set docUserUnitLength = Part.GetUserUnit(swLengthUnit)

                  Set docUserUnitVolume = Part.GetUserUnit(swUnitsMassPropVolume)

               

                  Debug.Print "  Full units name: " & docUserUnitAngle.GetFullUnitName(True)

                  Debug.Print "  Full units name: " & docUserUnitLength.GetFullUnitName(True)

                  Debug.Print "  Full units name: " & docUserUnitVolume.GetFullUnitName(True)

               

              End Sub

                • Re: Unit name for volume - swDmUnitsMassPropVolume_e
                  Deepak Gupta

                  Try these. Add other unit cases as needed.

                   

                  Dim swApp            As SldWorks.SldWorks
                  Dim swModel         As SldWorks.ModelDoc2
                  Dim sText               As String
                  
                  Sub main()
                  
                  Set swApp = Application.SldWorks
                  Set swModel = swApp.ActiveDoc
                  sText = "Tools > Options > Document Properties > Units > Volume unit is "
                  
                      Select Case swModel.Extension.GetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropVolume, _
                      swUserPreferenceOption_e.swDetailingNoOptionSpecified)
                          
                          Case 4
                               Debug.Print sText & "Millimeters3"
                          
                          Case 6
                              Debug.Print sText & "Meters3"
                              
                         Case 9
                              Debug.Print sText & "Inches3"
                  
                          Case 10
                              Debug.Print sText & "Feet3"
                      End Select
                  
                  End Sub