5 Replies Latest reply on Jun 17, 2015 3:00 AM by Hrituc Alexandru

    Macro to add Mass and Area Properties to all configurations

    Hrituc Alexandru

      Hello everyone,

                    I fail to create a macro that adds mass and area to specific config, more precisely, for all configration. How can i do this? Can someone help me?

       

      1.jpg

        • Re: Macro to add Mass and Area Properties to all configurations
          Deepak Gupta

          Try these codes:

           

          Option Explicit

              Dim swApp                    As SldWorks.SldWorks

              Dim swModel                 As SldWorks.ModelDoc2

              Dim vConfNameArr       As Variant

              Dim sConfigName         As String

              Dim i                              As Long

           

          Sub main()

              Set swApp = Application.SldWorks

              Set swModel = swApp.ActiveDoc

           

              vConfNameArr = swModel.GetConfigurationNames

           

              For i = 0 To UBound(vConfNameArr)

                  sConfigName = vConfNameArr(i)

                  swModel.AddCustomInfo3 sConfigName, "TArea", swCustomInfoText, Chr(34) + "SW-SurfaceArea" + Chr(34)

                  swModel.AddCustomInfo3 sConfigName, "Mass", swCustomInfoText, Chr(34) + "SW-Mass" + Chr(34)

              Next i

           

          End Sub

            • Re: Macro to add Mass and Area Properties to all configurations
              Hrituc Alexandru

              macro work, but he put the same values to mass and area on all configurations... It can not customize for each configuration in side?

               

              1.jpg

                • Re: Macro to add Mass and Area Properties to all configurations
                  Hrituc Alexandru

                  "SW-SurfaceArea@@CONFIG@Parttitle"

                  "SW-Mass@@CONFIG@Parttitle"

                   

                  from what I see in mass formula and the area is taken into account configuration and parttitle ....

                  how can write a code to automatically take information from specific config?

                   

                  i modify the code:

                   

                  Option Explicit

                      Dim swApp                    As SldWorks.SldWorks

                      Dim swModel                 As SldWorks.ModelDoc2

                      Dim vConfNameArr       As Variant

                      Dim sConfigName         As String

                      Dim i                              As Long

                          Dim A As String

                  Sub main()

                      Set swApp = Application.SldWorks

                      Set swModel = swApp.ActiveDoc

                   

                      vConfNameArr = swModel.GetConfigurationNames

                      swModel.GetTitle

                      For i = 0 To UBound(vConfNameArr)

                          sConfigName = vConfNameArr(i)

                          swModel.AddCustomInfo3 sConfigName, "TArea", swCustomInfoText, Chr(34) + "SW-SurfaceArea@@sConfigName@" + Chr(34)

                          swModel.AddCustomInfo3 sConfigName, "Mass", swCustomInfoText, Chr(34) + "SW-Mass@@sConfigName@" + Chr(34)

                      Next i

                   

                  End Sub

                   

                   

                  Now appear the config specific but for parttitle I have not yet succeeded

                   

                  swModel.Gettitle ... i try with this and it doesn't work

                    • Re: Macro to add Mass and Area Properties to all configurations
                      Deepak Gupta

                      Option Explicit

                          Dim swApp                   As SldWorks.SldWorks

                          Dim swModel                 As SldWorks.ModelDoc2

                          Dim vConfNameArr            As Variant

                          Dim sConfigName             As String

                          Dim i                       As Long

                          Dim sFileName               As String

                       

                      Sub main()

                          Set swApp = Application.SldWorks

                          Set swModel = swApp.ActiveDoc   

                          sFileName = Mid(swModel.GetPathName, InStrRev(swModel.GetPathName, "\") + 1)  

                          vConfNameArr = swModel.GetConfigurationNames

                          For i = 0 To UBound(vConfNameArr)

                              sConfigName = vConfNameArr(i)

                              swModel.AddCustomInfo3 sConfigName, "TArea12", swCustomInfoText, Chr(34) + "SW-SurfaceArea" + "@@" + sConfigName + "@" + sFileName + Chr(34)

                              swModel.AddCustomInfo3 sConfigName, "Mass12", swCustomInfoText, Chr(34) + "SW-Mass" + "@@" + sConfigName + "@" + sFileName + Chr(34)

                          Next i

                      End Sub