5 Replies Latest reply on May 14, 2012 4:19 PM by Germane Admin

    pack and go VBA crashing

    Germane Admin

      Trying to script Pack and GO in Solidworks.  I followed the API example in the Solidworks API document.  Every time it gets to the step on getting the Pack and GO interface it crashes swVBAserver. 


                Set swPackandGo = SwModelDocExt.GetPackAndGo 



      Solidworks reimains open, but I cannot re-open the SW script editor again until I restart Solidworks 2011.  Can anyone shed some light as to what's going on and how I can work around this?

        • Re: pack and go VBA crashing
          Keith Rice



          Are you using an unmodified macro example from the API Help or did you modify it?  If you modified it lets see your code.  Some other things you might try:


          1. Create a macro that only tests the pack and go functionality, so it removed from other factors that might be involved if your code is part of a larger macro.  Also, this way you can post it on the forums and it is easier for others to help you with.


          2. Try running that same code on a different computer.  If it works then there is obviously a conflict on your computer or a bad installation.



          Video Tutorials for the SolidWorks API

            • Re: pack and go VBA crashing
              Germane Admin

              Option Explicit

              Dim swApp As SldWorks.SldWorks

              Dim Document As ModelDoc2

              Dim Errors As Long

              Dim Warnings As Long

              Dim FileName As String

              Dim swPackandGo As PackAndGo

              Dim SwModelDocExt As ModelDocExtension



              Sub main()

              FileName = "c:\temp\part-old.SLDPRT"

                  Set swApp = Application.SldWorks


                  Set Document = swApp.OpenDoc6(FileName, swDocPART, swOpenDocOptions_ReadOnly, "", Errors, Warnings)

                  Set SwModelDocExt = Document.Extension


                  Set swPackandGo = SwModelDocExt.GetPackAndGo <----fails right here

                  SwModelDocExt.SavePackAndGo (Document)


              End Sub



              I'll have to try this on another computer and see if I get the same error.  Thanks for the reply!

              Btw, I wanted to test this with just a Part file to keep it simple.  So I modified some things from the API vb example code to get it to work with a part file.