13 Replies Latest reply on Nov 6, 2012 3:31 PM by Aj Jones

    Can you keep an assembly from rebuilding when opening it in API

    Aj Jones

      I have an API where an assembly is opened, and then then some mates in the assembly are changes based on the user input.  The problem is that every time the assembly is opened, the assembly rebuilds which takes about 22 more seconds and then it changes the mates.  I've tried using the EnableAssemblyRebuild command, but it is still rebuilds, and I also tried using the method from this thread https://forum.solidworks.com/thread/21333

       

      Here is the beginning of my code to open up an assembly.


      Set Part = swApp.ActiveDoc
      Set Part = swApp.OpenDoc6("Z:\chassis\part22.SLDPRT, 2, 0, "", longstatus, longwarnings)
      boolstatus = swApp.SetUserPreferenceIntegerValue(swRebuildOnActivation, swDontRebuildActiveDoc)

       

      With that code, everytime part22 is opened, it automatically starts rebuilding, and I don't want it to.

       

      Thanks

        • Re: Can you keep an assembly from rebuilding when opening it in API
          Jim Sculley

          Have you tried setting the system integer option:

           

          swPerformanceAssemRebuildOnLoad

           

          to

           

          swPromptAlwaysNever.swResponseNever?

           

          See System Options and Document Properties for details.

           

          Jim S.

            • Re: Can you keep an assembly from rebuilding when opening it in API
              Aj Jones

              I looked up the System Options and Document Properties and I came up with this, but I still can't get it to work

               

              Dim instance As ISldWorks
              Dim UserPreferenceValue As Integer
              Dim value As Integer
              'Dim value As Boolean

              value = instance.SetUserPreferenceIntegerValue(swPerformanceAssemRebuildOnLoad, swPromptAlwaysNever.swResponseNever)

              Set Part = swApp.ActiveDoc
              Set Part = swApp.OpenDoc6("Z:\chassis\Part22.SLDPRT, 2, 2, "", longstatus, longwarnings)

               

              Thanks for the quick response!

                • Re: Can you keep an assembly from rebuilding when opening it in API
                  Aj Jones

                  Actually I got it to work now, and it does change the system options to Never, but the assembly still rebuilds when it gets opened by solidworks.  I even manually put it to never, and it still rebuilds while opening.

                  • Re: Can you keep an assembly from rebuilding when opening it in API
                    Jim Sculley

                    Use OpenDoc7 instead of OpenDoc6.  It seems to respect the user preferences.

                     

                    Dim swApp As SldWorks.SldWorks

                    Dim swModel As SldWorks.ModelDoc2

                    Dim spec As DocumentSpecification

                    Dim status As Boolean

                     

                    Sub main()

                        Set swApp = Application.SldWorks

                        status = swApp.SetUserPreferenceIntegerValue(swUserPreferenceIntegerValue_e.swPerformanceAssemRebuildOnLoad, swPromptAlwaysNever_e.swResponseNever)

                        Set spec = swApp.GetOpenDocSpec("Part1.sldprt")

                        Set swModel = swApp.OpenDoc7(spec)

                    End Sub

                     

                    Also, if your code will be used by others, be sure to store the original value of the user preference and then set it back to its original value when you are done.

                     

                    Jim S.

                      • Re: Can you keep an assembly from rebuilding when opening it in API
                        Aj Jones

                        Thanks Jim that worked without the assembly rebuilding.  For some reason, it is still taking a long time for the assembly to load.  If I manually open the assembly in SolidWorks, it takes 24 seconds for it to open.  When I run the program with OpenDoc7 it is taking about 52 seconds to load.  This is about the same amount of time it was taking for OpenDoc6 to open the assembly and rebuild it.  All I have the code doing currently is opening the model and that is it.  Would you know of any reason why it would take longer?

                  • Re: Can you keep an assembly from rebuilding when opening it in API
                    K. C

                    Hi Jones

                     

                    Before Debugging Change the settings

                    You can find the below image in

                    Solidworks Menu--->Tools------->Options---->Then  you can find the below image settings

                     

                     

                     

                    untitled.bmp

                     

                     

                    Regards

                    K.C

                      • Re: Can you keep an assembly from rebuilding when opening it in API
                        Aj Jones

                        Thanks K. C.  This does work, but the only problem for my case is that this program will be used on other computers as well that may or may not have that option selected in their settings.

                          • Re: Can you keep an assembly from rebuilding when opening it in API
                            Artem Taturevych

                            Dim curVal as Integer

                            curVal = swApp.GetUserPreferenceToggle(swUserPreferenceToggle_e.swLargeAsmModeSuspendAutoRebuild)

                             

                            swApp.SetUserPreferenceToggle(swUserPreferenceToggle_e.swLargeAsmModeSuspendAutoRebuild, True)

                             

                            'TODO: Put your code here. Opening and so on

                             

                            'Restore the user preferences

                            swApp.SetUserPreferenceToggle(swUserPreferenceToggle_e.swLargeAsmModeSuspendAutoRebuild, curVal)

                             

                            ______________________

                            Regards,

                            Artem Taturevych

                            Application Engineer at Intercad

                            http://intercad.com.au/

                            Tel: +61 2 9454 4444

                              • Re: Can you keep an assembly from rebuilding when opening it in API
                                Aj Jones

                                Artem, I used the code you have shown above but I had to add "curVal =" in front of the 4th line because I got an error on the 4th and 5th line of code that you have above.  I'm guessing that is correct?  However when I did run the code, using OpenDoc6 after the 4th line of code you have shown above it was still rebuilding.  I find it odd that I can manually cut off automatic rebuild or try it in the API and either way it always shows it rebuilding.  Thank you though

                                  • Re: Can you keep an assembly from rebuilding when opening it in API
                                    Artem Taturevych

                                    Excuse me I confused. Do you say that you add the open call after all these lines? Can you post the snippet you have? This curVal variable is only used to restore the setting after opening (it is a good practice to return the options which changed by macro). As the test just try to put the following line just before opening. This will enables the toggle which you said before works for you:

                                     

                                    swApp.SetUserPreferenceToggle(swUserPreferenceToggle_e.swLargeAsmModeSuspendAutoRebuild, True)

                                    ______________________

                                    Regards,

                                    Artem Taturevych

                                    Application Engineer at Intercad

                                    http://intercad.com.au/

                                    Tel: +61 2 9454 4444

                                      • Re: Can you keep an assembly from rebuilding when opening it in API
                                        Aj Jones

                                        This is what happens when I paste the code, it gives me two errors.  I hilighted the two lines that give errors.  I tried adding "CurVal = in front of those two lines so that they would not have errors anymore.  I don't know if that was the right thing to do or not?  The code below is in being ran in the Visual Basic editor, not Visual Studio.  It is just a .swp.  I don't know if that makes a difference or not?  Thanks!

                                         

                                        Option Explicit

                                        Dim swApp As Object
                                        Dim Part As Object
                                        Dim boolstatus As Boolean
                                        Dim longstatus As Long, longwarnings As Long

                                        Sub main()

                                        Set swApp = _
                                        Application.SldWorks

                                        Set Part = swApp.ActiveDoc

                                        Dim Doc As SldWorks.ModelDoc2
                                        Dim boolstatus As Boolean

                                        Set swApp = Application.SldWorks
                                        Set Doc = swApp.ActiveDoc
                                        Dim Assem As SldWorks.AssemblyDoc


                                        Dim curVal As Integer

                                        curVal = swApp.GetUserPreferenceToggle(swUserPreferenceToggle_e.swLargeAsmModeSuspendAutoRebuild)


                                        swApp.SetUserPreferenceToggle(swUserPreferenceToggle_e.swLargeAsmModeSuspendAutoRebuild, True)


                                        Set Part = swApp.OpenDoc6("Z:\Test\TestAssembly.SLDASM", 2, 0, "", longstatus, longwarnings)

                                        'Restore the user preferences

                                        swApp.SetUserPreferenceToggle(swUserPreferenceToggle_e.swLargeAsmModeSuspendAutoRebuild, curVal)


                                        End Sub

                                          • Re: Can you keep an assembly from rebuilding when opening it in API
                                            Artem Taturevych

                                            Hi Aj,

                                             

                                            Yes, in this particular case it makes the difference. In VBA you should not use parenthesis if you are not getting the return. Should be like the following:

                                             

                                            Dim curVal As Integer

                                            curVal = swApp.GetUserPreferenceToggle(swUserPreferenceToggle_e.swLargeAsmModeSuspendAutoRebuild)


                                            swApp.SetUserPreferenceToggle swUserPreferenceToggle_e.swLargeAsmModeSuspendAutoRebuild, True


                                            Set Part = swApp.OpenDoc6("Z:\Test\TestAssembly.SLDASM", 2, 0, "", longstatus, longwarnings)

                                            'Restore the user preferences

                                            swApp.SetUserPreferenceToggle swUserPreferenceToggle_e.swLargeAsmModeSuspendAutoRebuild, curVal


                                            End Sub

                                             

                                            ______________________

                                            Regards,

                                            Artem Taturevych

                                            Application Engineer at Intercad

                                            http://intercad.com.au/

                                            Tel: +61 2 9454 4444