7 Replies Latest reply on Jan 16, 2016 5:51 AM by Arif Akbas

    How to add material weight

    Arif Akbas

      Is that weights may be automatically x2 materials list?

      How equation is established

      How to add material weight

       

       

       

       

      1.JPG

       

       

      2.JPG

        • Re: How to add material weight
          Viktor Bovzdarenko

          Try this one

          Mass is added in document units

           

          Dim swApp       As Object

          Dim swModel     As SldWorks.ModelDoc2

           

           

          Dim boolstatus  As Boolean

           

           

          Sub Main()

              Set swApp = Application.SldWorks

              Set swModel = swApp.ActiveDoc

              Dim MyMassProp              As SldWorks.MassProperty

              Dim SwConfig                As Configuration

              Dim swMass                  As Double

              Set swApp = CreateObject("SldWorks.Application")

              Set swModel = swApp.ActiveDoc

              Set MyMassProp = swModel.Extension.CreateMassProperty

              MyMassProp.UseSystemUnits = False

              swMass = MyMassProp.Mass

              swMass = Round(swMass, 2) * 2

              Set SwConfig = swModel.GetActiveConfiguration

              code = SwConfig.CustomPropertyManager.Add3("Mass", swCustomInfoText, swMass, swCustomPropertyReplaceValue)

          End Sub

           

          Property "mass" is added to your active configuration

          Can change the name of the property:

           

          code = SwConfig.CustomPropertyManager.Add3("Mass", swCustomInfoText, swMass, swCustomPropertyReplaceValue)

          • Re: How to add material weight
            Arif Akbas

            HOW TO

            Have examples

              • Re: How to add material weight
                Arif Akbas

                Set kg

                As results came 1750000000

                  • Re: How to add material weight
                    Viktor Bovzdarenko

                    Dim swApp       As Object

                    Dim swModel     As SldWorks.ModelDoc2

                    Dim MyMassProp  As SldWorks.MassProperty

                    Dim swMass      As Double

                    Dim code        As Integer

                    Sub Main()

                        Set swApp = Application.SldWorks

                        Set swModel = swApp.ActiveDoc

                        Set swApp = CreateObject("SldWorks.Application")

                        Set swModel = swApp.ActiveDoc

                        Set MyMassProp = swModel.Extension.CreateMassProperty

                        MyMassProp.UseSystemUnits = False

                        Debug.Print "Measured mass: " & Round(MyMassProp.Mass)

                        swMass = Round(MyMassProp.Mass / 1000, 2) * 2

                        Debug.Print "Added custom property: & "; "Mass  =  " & swMass & " kg"

                        code = swModel.GetActiveConfiguration.CustomPropertyManager.Add3("Mass", swCustomInfoText, swMass & " kg", swCustomPropertyReplaceValue)

                    End Sub

                • Re: How to add material weight
                  Arif Akbas

                  It did not work

                  Have you tried

                    • Re: How to add material weight
                      Viktor Bovzdarenko

                      what exactly did not work?

                      You should see in immediate window the following info:

                      and added custom property in your active document and active configuration:

                       

                       

                       

                      please try again

                       

                      Dim swApp       As Object

                      Dim swModel     As SldWorks.ModelDoc2

                      Dim MyMassProp  As SldWorks.MassProperty

                      Dim swMass      As Double

                      Dim code        As Integer

                      Sub Main()

                          Set swApp = Application.SldWorks

                          Set swModel = swApp.ActiveDoc

                          Set swApp = CreateObject("SldWorks.Application")

                          Set swModel = swApp.ActiveDoc

                          Set MyMassProp = swModel.Extension.CreateMassProperty

                          MyMassProp.UseSystemUnits = False

                          Debug.Print "Measured mass: " & Round(MyMassProp.Mass)

                          swMass = Round(MyMassProp.Mass / 1000, 2) * 2

                          Debug.Print "Added custom property: & "; "Mass  =  " & swMass & " kg"

                          code = swModel.GetActiveConfiguration.CustomPropertyManager.Add3("Mass", swCustomInfoText, swMass & " kg", swCustomPropertyReplaceValue)

                      End Sub