2 Replies Latest reply on Jan 29, 2016 8:13 AM by Laura Arns

    Delete Waterjet Configuration API help

    Laura Arns

      The macro ran beautifully a few times, and now it's coming up with an error on the line with PartConfigs = CmpDoc.GetConfigurationNames()

       

      Nobody has changed the macro, and the parts I'm running are similar to the ones I ran before. Before this is run, we've opened an assembly, and run a script to go through each part within it, check for certain material types that would be run on the waterjet, create a waterjet configuration for those parts, undersize certain holes appropriately and suppress certain features within that configuration, then export a DXF of the largest face. When it finds a waterjet configuration already present, it just goes ahead and exports the face without updating for added holes or anything else. This tool is meant to be used in the main assembly, looking at each part within it, and deleting any waterjet configurations within them.

       

      What can change the stability of a macro from one run to the next? How can I change this macro to be more stable? Somebody else did it initially so I'd also appreciate help fully understanding for instance why a temporary assembly needs to be created, or what the "(False)" in "myAsy.GetComponents(False)" is for. Below is the code:

       

      Sub DeleteWJConfigB()

       

          Dim swApp As SldWorks.SldWorks

          Dim Assembly As ModelDoc2

          Dim CmpDoc  As ModelDoc2

          Dim myCmps

          Dim i As Long

          Dim myCmp As Component2

          Dim PartConfigs As Variant

         

          Set swApp = Application.SldWorks 'Tell VBA that you are using SolidWorks

          Set Assembly = swApp.ActiveDoc 'Select the open assembly

          Set myAsy = Assembly            'myAsy is a temporary assembly

       

      'Get all the components in the assembly

      myCmps = myAsy.GetComponents(False)

       

      'Cycle through all the components of the assembly

      For i = 0 To UBound(myCmps)

         

          'Temporarily sets myCmp as the "Active" part

          Set myCmp = myCmps(i)

          'Get the model information of the active part

          Set CmpDoc = myCmp.GetModelDoc

          'Get all the configuration names of the active part

          PartConfigs = CmpDoc.GetConfigurationNames()

         

       

          'Macro only runs on parts with more than 1 configuration (this was just to save some time)

          If UBound(PartConfigs) > 0 Then

         

              'Activate the default configuration (You cannot delete the waterjet config if it is active

              ConfigName = CmpDoc.ShowConfiguration2("Default")

              'Delete the waterjet configuration

              ConfigName = CmpDoc.DeleteConfiguration2("Waterjet")

       

          End If

       

      Next i

       

      'User Feedback

      MsgBox ("Operation Complete")

       

      End Sub

        • Re: Delete Waterjet Configuration API help
          Artem Taturevych

          Hi Laura,

           

          Two thing which may stop this macro. You assembly has suppressed components or your assembly is lightweight.

           

          Add the lines in bold to your macro.

           

          'Get all the components in the assembly

          myAsy.ResolveAllLightWeightComponents True

          myCmps = myAsy.GetComponents(False)

          and

           

              Set CmpDoc = myCmp.GetModelDoc

              If Not CmpDoc Is Nothing Then

              'Get all the configuration names of the active part

              PartConfigs = CmpDoc.GetConfigurationNames()

            

           

              'Macro only runs on parts with more than 1 configuration (this was just to save some time)

              If UBound(PartConfigs) > 0 Then

            

                  'Activate the default configuration (You cannot delete the waterjet config if it is active

                  ConfigName = CmpDoc.ShowConfiguration2("Default")

                  'Delete the waterjet configuration

                  ConfigName = CmpDoc.DeleteConfiguration2("Waterjet")

           

              End If

              End If

          Thanks,
          Artem