7 Replies Latest reply on Jul 3, 2017 2:30 AM by Deepak Gupta

    Assign Weight, Area to a custom property

    Sanya Shmidt

      Hello guys,

      can you please help me with this, I need macro to assign weight and area to the part custom properties. What I have is below,

       

      If swModel.CustomInfo2("", "Weight") = "" Then

               retval = swModel.AddCustomInfo3("", "Weight", swCustomInfoText, "=")

      End If

      If swModel.CustomInfo2("", "Area") = "" Then

               retval = swModel.AddCustomInfo3("", "Area", swCustomInfoText, "=")

      End If

       

        ' weight Is there an easier way to assign : SW-Mass???

        Dim Density As Double

        swModel.CustomInfo("Weight") = swModel.GetMassProperties(HOWTOGETDENSITY) * 2.20462262

       

      swModel.CustomInfo("Area") = swModel..... Not even sure how to get area  "SW-SurfaceArea"

       

       

       

      I tried the following as well

       

      Dim nStatus As Long

      Dim swModelExt As SldWorks.ModelDocExtension

      Set swModelExt = swModel.Extension

      VmassProp = swModelExt.GetMassProperties(1, nStatus)

       

      ' weight

      swModel.CustomInfo("Weight") = VmassProp(5) 

       

      ' Area

      swModel.CustomInfo("Area") = VmassProp(4)

       

      If I do this the numbers doesnt make any sense..


       

      Any help appreciated.

       

       

      Thank you.

        • Re: Assign Weight, Area to a custom property
          Deepak Gupta

          Try  these codes:

           

          Dim swApp       As SldWorks.SldWorks

          Dim swModel     As SldWorks.ModelDoc2

          Sub main()

           

          Set swApp = Application.SldWorks

          Set swModel = swApp.ActiveDoc

           

           

              If swModel.CustomInfo2("", "Weight") = "" Then

                   retval = swModel.AddCustomInfo3("", "Weight", swCustomInfoText, Chr(34) & "SW-Mass" & Chr(34))

                 Else

                   swModel.CustomInfo2("", "Weight") = Chr(34) & "SW-Mass" & Chr(34)

              End If

           

              If swModel.CustomInfo2("", "Area") = "" Then

                   retval = swModel.AddCustomInfo3("", "Area", swCustomInfoText, Chr(34) & "SW-SurfaceArea" & Chr(34))

                 Else

                   swModel.CustomInfo2("", "Area") = Chr(34) & "SW-SurfaceArea" & Chr(34)

              End If

           

          End Sub