15 Replies Latest reply on Aug 13, 2017 7:51 AM by Deepak Gupta

    Macro to create configurations

    Andrea Arfelli

      Good morning everyone,

       

      this is my question:

       

      I have a file part composed by n bodies, I have to create a configuration for each body in the file (using the "remove body").

      it's possible? you have any advice? existing macro?

       

      Thank you all

        • Re: Macro to create configurations
          Viktor Bovzdarenko

          Hi. Here is required macro

           

          'Central Innovation

          'http://www.centralinnovation.com.au/

          'Disclamer: The API examples are provided as is and should be used as reference only.

          'In no event shall Central Innovation be liable for any types of damages whatsoever

          '(including without limitation, damages from the loss of use, data, profits, or business)

          'arising out of the uses of this information, applications, or services.

           

           

          Option Explicit

          Dim swApp As SldWorks.SldWorks

          Dim swModel As ModelDoc2

          Dim swPart As IPartDoc

           

           

          Dim SelMgr As SelectionMgr

          Dim swSelData As SldWorks.SelectData

          Dim ConfigMgr As ConfigurationManager

          Dim config As IConfiguration

          Dim allConfigurations As New Collection

          Dim myFeature As SldWorks.Feature

           

           

          Dim allbodies As Variant

          Dim swBody As SldWorks.Body2

          Dim boolstatus As Boolean

          Dim p As Integer

          Dim n As Integer

           

           

          Sub main()

              Set swApp = Application.SldWorks

              Set swModel = swApp.ActiveDoc

              Set swPart = swModel

             

              Set SelMgr = swModel.SelectionManager

              Set swSelData = SelMgr.CreateSelectData

              Set ConfigMgr = swModel.ConfigurationManager

              Dim configname As String

             

              allbodies = swPart.GetBodies2(swSolidBody, False)

             

              For p = 0 To UBound(allbodies)

                  configname = "Config_" & p

                  Set config = ConfigMgr.AddConfiguration(configname, "", "", 1, "", "")

                  allConfigurations.Add config

              Next p

              For p = 0 To UBound(allbodies)

                  Set config = allConfigurations(p + 1)

                  swModel.ShowConfiguration2 (config.Name)

           

           

                  For n = 0 To UBound(allbodies)

                      Set swBody = allbodies(n)

                      If Not n = p Then

                          boolstatus = swBody.Select2(True, swSelData)

                      End If

                  Next n

                  Set myFeature = swModel.FeatureManager.InsertDeleteBody2(False)

                  myFeature.SetSuppression2 swSuppressFeature, swAllConfiguration, Nothing

                  myFeature.SetSuppression2 swUnSuppressFeature, swThisConfiguration, Nothing

                  swModel.ClearSelection2 True

              Next p

          End Sub