5 Replies Latest reply on Oct 7, 2015 9:56 AM by Simon Dubois

    Problem opening an asm driven by a design table

    Simon Dubois

      Hellow !

       

      I'm trying to open an asm in VBA (from an external excel file).

      This asm is driven by a design table to put some cinderblock on a plank.

      The plank is driven by a design table to set its dimensions.

      The cindeblocks are driven by design table to set their dimensions.

       

      When I try to open the asm, solidworks automatically :

      - opens the asm, opens its design table, closes its design table.

      - opens the plank, opens its design table, closes its design table, updates the plank.

      - opens the cinderblocks, opens their design table, closes their design table, updates the cindeblocks.

      - update the asm.

       

      The problem is : Because of opening all these excel file while a macro is running in another one, 7 out of 10 times it crashes.

       

      Here is the code :

       

      Private Sub CommandButton1_Click()


      Dim longstatus As Long
      Dim longwarnings As Long
      Dim swApp As SldWorks.SldWorks
      Dim swPart1 As SldWorks.ModelDoc2
      Dim swPart2 As SldWorks.ModelDoc2
      Dim swPart3 As SldWorks.ModelDoc2

       

      On Error Resume Next

       

      Set swApp = GetObject(, "SldWorks.Application")


      If Err.Number = 0 Then
      Else
          If MsgBox("Veuillez lancer Solidworks avant d'ouvrir la MEP.", 0 + 4096 + 48, "Attention") = True Then
          End If
          Exit Sub
      End If

       

      Set swPart1 = swApp.OpenDoc6(PathCinderblock, 1, 0, "", longstatus, longwarnings)
      DoEvents
      Set swPart2 = swApp.OpenDoc6(PathPlank,1, 0, "", longstatus, longwarnings)
      DoEvents
      Set swPart3 = swApp.OpenDoc6(PathASM, 2, 0, "", longstatus, longwarnings)
      DoEvents
      End Sub

       

      At the beginning, I tried directly opening the ASM, and opening solidworks with Set swApp = New SldWorks.SldWorks, it worked sometimes, but it seemed to crash even more frequently.

       

      So I tried how it is above. But again, it crashes frequently.

       

      Does someone have a solution to this problem ?

       

      Thank you,

       

      Simon

       

      PS : Don't mind my English, I'm not very good at it.

        • Re: Problem opening an asm driven by a design table
          Peter Brinkhuis

          What lines cause the design table to be opened and closed? I use the following code to test for the existence of a design table, it opens and closes it immediately.

           

              Set swDesTable = swModel.GetDesignTable

              bRet = swDesTable.Attach

              If bRet Then

                 swDesTable.Detach

               end if

           

          According to https://support.microsoft.com/en-en/kb/118468 the command "doevent" causes the program to continue instead of wait. I think it will run more smoothly if those lines are removed, although it may take longer.

            • Re: Problem opening an asm driven by a design table
              Simon Dubois

              Thanks Peter,

               

              Peter Brinkhuis:

               

              What lines cause the design table to be opened and closed?

               

              No one. It's solidworks which, at the opening of the file, opens the various design table and closes it to check if there is update to do on the part.

              Actually, this action don't mind me. I want Solidworks updating part at their opening. But I was wondering if it has a way to do it hidden.

               

              Maybe what I can try is : Disable the automatic opening of the design table at the opening of the part or asm. Open the 3 elements, and when they are opened, updating them (open/close their design table) one by one.

               

              But I don't really know what is the VBA code for this.

               

              Peter Brinkhuis:

               

              According to https://support.microsoft.com/en-en/kb/118468 the command "doevent" causes the program to continue instead of wait. I think it will run more smoothly if those lines are removed, although it may take longer.

              Oh. I knew I hadn't totally understund how this command was running. I just tried it before posting here. It don't matter if I write it or not, crashes are still there.:x

            • Re: Problem opening an asm driven by a design table
              Simon Dubois

              Ok, after a few test I know exactly what happens :

               

                    If a macro is running (in excel) while solidworks checks the design table : excel crashes. Even if it's just a Sleep.

               

              The problem is : My macro open solidworks, open a drawing (drawing of the asm and the parts), and interact with it.

               

              I know I can open soldiworks and the drawing thanks to a macro, then interact with it thanks to another, but I would like both being done in just one.

               

               

              EDIT : It's a bit more complicated actually... or maybe not :

                   The excel file is my interface for setting the three design table. It has vaious sub.

                   When I just open the excel file and open solidworks (thanks to a macro), excel doesn't crash.

                   When I open the excel file, I run some more sub (without running sub which edit the design table), and I open solidworks (always with the same macro) excel crashes.

               

              I don't know much about memory process, but it seems that the problem is link to this.

               

              Does anyone know about it ?

               

              Thank you,

               

              EDIT 2 : Ok, with excel in safe mode, and my interface already filled (so, I havn't run any macro before running the one which open solidworks and intreact with the drawing), it hadn't crash.

               

              So there is no problem in my code, which is a very good news !

              But it really seems to be a memory problem (all my pointers already are set to nothing, I don't know what I can do more )