7 Replies Latest reply on Jun 15, 2015 11:57 AM by Matt Tolson

    Dissolve Component Pattern VB

    Matt Tolson

      I am trying to dissolve patterns in the Feature Manager Design Tree through a vb program. I could not find an example in the api on how to do this.  I only found the dissolvecomponentpattern function.  I have the following code currently, but when I dissolve it deletes the assembly.

       

       

              swFeat = swModel.FirstFeature

              While Not swFeat Is Nothing

                  Debug.Print(swFeat.Name)

                  If swFeat.Name.Contains("Pattern") Then

                      swFeat.Select(False)

                      swModelDoc = swModel

                      swModelDoc.DissolveComponentPattern()

                  End If

                  swSubFeat = swFeat.GetFirstSubFeature

                  While Not swSubFeat Is Nothing

                      Debug.Print("    " & swSubFeat.Name)

                      swSubFeat = swSubFeat.GetNextSubFeature

                  End While

                  swFeat = swFeat.GetNextFeature

              End While

       

       

          End Sub

        • Re: Dissolve Component Pattern VB
          Keith Rice

          For problems like this, it is best to try to create a separate macro that only dissolves the component pattern, in order to understand how that aspect works. Then you can integrate back into your traverse code. For example, create a new VB.NET macro with the following code, select a component pattern, and run the macro:

           

          Imports SolidWorks.Interop.sldworks
          Imports SolidWorks.Interop.swconst
          Imports System.Runtime.InteropServices
          Imports System
          
          Partial Class SolidWorksMacro
          
              Public Sub main()
                  Dim swModel As ModelDoc2 = swApp.ActiveDoc
                  Dim swAssy As AssemblyDoc = swModel
                  swAssy.DissolveComponentPattern()
              End Sub
          
              Public swApp As SldWorks
          
          End Class
          

           

          Keith

          SolidWorks API Tutorials

          • Re: Dissolve Component Pattern VB
            Matt Tolson

            I have modified my originally posted code with the code below.  I was having two issues. 

            1. The first issue was that I had to run this code on each assembly.  If I tried to traverse the top level assembly only, it would not select the component pattern in the feature manager.  
            2. The second issue was I needed to filter out certain pattern types.  As seen below I used the "GetTypeName2" function to get the pattern I wanted and then I was successfully able to dissolve the component pattern.
             swFeat = swModel.FirstFeature
             While Not swFeat Is Nothing
                 Debug.Print(sPadStr + swFeat.Name + " [" + swFeat.GetTypeName2 + "]")
                 b = False
                 If swFeat.GetTypeName2.Contains("HolePattern") Or swFeat.GetTypeName2.Contains("LPattern") Then
                      Debug.Print(swFeat.Name)
                      b = swFeat.Select2(False, 0)
                      If b = True Then
                           swFeat = swFeat.GetNextFeature
                      End If
                      swModelDoc = swModel
                      swModelDoc.DissolveComponentPattern()
                 End If
                 If b = False Then
                      swFeat = swFeat.GetNextFeature
                 End If
             End While