3 Replies Latest reply on Sep 16, 2016 7:13 AM by Keith Rice

    API SetAutomaticUpdate

    Derek Eldridge

      Please help.

       

      I'm writing a VBA macro that will set the values for AutomaticCutList and AutomaticUpdate of the cut list to False.

      Using SetAutomaticUpdate from the API.

      The 2016 API gives a straightforward example at:

      2016 SOLIDWORKS API Help - Get Features of Multibody Sheet Metal Part Example (VBA)

       

      I've used this example and changed the following two lines to False:

                  swBodyFolder.SetAutomaticCutList False

                  swBodyFolder.SetAutomaticUpdate False

       

      When the debug Prints the values for each, SetAutomaticUpdate remains True.

      For some reason, I can't figure out why SetAutomaticUpdate wont change.

       

       

      My End game is a macro that will run through an entire assembly, looking for parts that have these features turned on, and turn them off. My rebuild of the top level assy is giving me a message to disable the option to increase performance.

        • Re: API SetAutomaticUpdate
          Viktor Bovzdarenko

          HI Derek

          The macro in the example was supposed to work with parts only. Also, I thought that we need to disable only SetAutomaticUpdate  to increase the performance.
          I tried the macro from the example and it work for a part:

          Sub main()

              Dim i As Long, j As Long

              Dim swApp As SldWorks.SldWorks: Set swApp = Application.SldWorks

              Dim swModel As SldWorks.ModelDoc2: Set swModel = swApp.ActiveDoc

              Dim swFeatMgr As SldWorks.FeatureManager: Set swFeatMgr = swModel.FeatureManager

              Dim swFeat As SldWorks.Feature: Set swFeat = swModel.FirstFeature

              Do While Not swFeat Is Nothing

                  If swFeat.GetTypeName2 = "CutListFolder" Then

                      Dim swBodyFolder As SldWorks.BodyFolder: Set swBodyFolder = swFeat.GetSpecificFeature2

                      swBodyFolder.SetAutomaticUpdate False

                  End If

                  Set swFeat = swFeat.GetNextFeature

              Loop

          End Sub

           

          To make it work with assembly you should get and process each component  Here is the example:

           

          Sub main()

              Dim i As Long, j As Long

              Dim swApp As SldWorks.SldWorks: Set swApp = Application.SldWorks

              Dim swModel As SldWorks.ModelDoc2: Set swModel = swApp.ActiveDoc

              Dim swAssem As SldWorks.AssemblyDoc: Set swAssem = swModel

              Dim vComponents As Variant: vComponents = swAssem.GetComponents(True)

              For i = 0 To UBound(vComponents)

                  Dim swChildModel As SldWorks.ModelDoc2: Set swChildModel = vComponents(i).GetModelDoc2

                  Dim swFeatMgr As SldWorks.FeatureManager: Set swFeatMgr = swChildModel.FeatureManager

                  Dim swFeat As SldWorks.Feature: Set swFeat = swChildModel.FirstFeature

                  Do While Not swFeat Is Nothing

                      If swFeat.GetTypeName2 = "CutListFolder" Then

                          Dim swBodyFolder As SldWorks.BodyFolder: Set swBodyFolder = swFeat.GetSpecificFeature2

                          swBodyFolder.SetAutomaticUpdate False

                      End If

                      Set swFeat = swFeat.GetNextFeature

                  Loop

              Next i

          End Sub

          • Re: API SetAutomaticUpdate
            Keith Rice
            'Turns off automatic cutlist updating in all weldment parts in an assembly.
            
            'Preconditions: Assembly is open
            'Results: See immediate window.
            
            'Notes:
            '-If you want the changes to the part saved, un-comment the line
            '   containing IModelDoc2::Save3.
            '-This does not consider duplicates. A part will be processed as
            '   many times as it exists in the assembly.
            '-Technically, only sheet metal and weldment parts have cut lists,
            '   but for simplicity this macro still traverses all parts.
            
            'Written by Keith Rice
            'CADSharp LLC
            'www.cadsharp.com
            
            Sub main()
                Dim swApp As SldWorks.SldWorks
                Dim swModel As SldWorks.ModelDoc2
                Dim swAssy As SldWorks.AssemblyDoc
                Dim swComp As SldWorks.Component2
                Dim swCompModel As SldWorks.ModelDoc2
                Dim vComps As Variant
                Dim i As Integer
                
                Set swApp = Application.SldWorks
                Set swModel = swApp.ActiveDoc
                
                If swModel Is Nothing Then Exit Sub
                If swModel.GetType <> swDocASSEMBLY Then Exit Sub
                
                Set swAssy = swModel
                
                vComps = swAssy.GetComponents(False)
                
                If IsEmpty(vComps) Then Exit Sub
                
                For i = 0 To UBound(vComps)
                    Set swComp = vComps(i)
                    Set swCompModel = swComp.GetModelDoc2
                    
                    If swCompModel Is Nothing Then
                        Debug.Print "Couldn't process component (lightweight or suppressed): " & swComp.Name2
                    Else
                        Debug.Print "Processing component: " & swComp.Name2
                        If swCompModel.GetType = swDocPART Then DisableAutomaticUpdates swCompModel
                    End If
                Next i
            End Sub
            
            Private Sub DisableAutomaticUpdates(swModel As SldWorks.ModelDoc2)
                Dim swFeat As SldWorks.Feature
                Dim swBodyFolder As SldWorks.BodyFolder
                Set swFeat = swModel.FirstFeature
                Do While Not swFeat Is Nothing
                    If swFeat.GetTypeName = "CutListFolder" Then
                        Set swBodyFolder = swFeat.GetSpecificFeature2
                        swBodyFolder.SetAutomaticUpdate False
                        'swCompModel.Save3 swSaveAsOptions_Silent, Empty, Empty
                        Exit Sub
                    End If
                    Set swFeat = swFeat.GetNextFeature
                Loop
            End Sub
            

             

            Keith

            SolidWorks API Training and Services