3 Replies Latest reply on Mar 19, 2014 1:45 PM by Jeroen Janssen Andeweg

    Opening Solidworks 2013 Std - 64bit API discrepancy

    Jeroen Janssen Andeweg

      Hello all,

       

      This morning I have started looking into the API of Solidworks and made a small app; opening and closing Solidworks.

       

      My code:

       

      Imports SolidWorks.Interop.sldworks
      Imports System.Runtime.InteropServices


      Public Class Form1

          Dim swApp As SldWorks
         
          Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

             
              Try
                  swApp = Marshal.GetActiveObject("SLDWORKS.Application.21")
                  'swApp = CType(System.Runtime.InteropServices.Marshal.GetActiveObject("SldWorks.Application"), SldWorks)
                 
                  MsgBox("Solidworks is already running.")
                 
              Catch ex As Exception
                 
                  swApp = DirectCast(Activator.CreateInstance(Type.GetTypeFromProgID("SLDWORKS.Application.21")), SldWorks)
                  swApp.Visible = True
              End Try

          End Sub

             Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

              Try
                  swApp = Marshal.GetActiveObject("SLDWORKS.Application")
                  'swApp = CType(System.Runtime.InteropServices.Marshal.GetActiveObject("SldWorks.Application"), SldWorks)
                  swApp.ExitApp()
              Catch ex As Exception
                  MsgBox("Solidworks is already closed.")
              End Try

          End Sub
       
      End Class

       

       

      I know there are different ways of getting this up and running but this is my test environment.

      Whatever I do this is not working correctly.

      - Yes it opens Solidwork when it is not running (ISSUE_01): Click Button1 again and the message does not show. That means there is something wrong with ("SLDWORKS.Application.21") but I don't know what. I have tried ("SLDWORKS.Application"), ("SldWorks.Application.21"), ("SldWorks.Application") but the message will not come up.

      The message will appear when I start Solidworks from my desktop shortcut and all ("SLDWORKS.Application.21"), ("SLDWORKS.Application"), ("SldWorks.Application.21"), ("SldWorks.Application") are recognised. The thing is my app starts Solidworks using the same ("SLDWORKS.Application") or any other variant.

       

      - Yes it opens Solidwork when it is not running (ISSUE_02): but is not the same as when I use my desktop shortcut.

       

      SldwDesktoplnk.png

      This is opening using Desktop shortcut, my app can close this one

       

       

      SldwApplnk.png

      This is openiing using App, my app does nothing with this one

       

      I am using Solidworks 2013 Std 64bit

       

      Any clarification in this matter is much appreciated

        • Re: Opening Solidworks 2013 Std - 64bit API discrepancy
          Jeroen Janssen Andeweg

          I have come to the conclusion that there is something wrong in the SolidWorks.Interop.sldworks.dll.

          I have put a copy of the SolidWorks.Interop.sldworks.dll in the debug folder where my .exe is. The session that opens with my app looks a bit different again, pretty much the same as before but without the ribbon.

           

          swApp = Marshal.GetActiveObject("SLDWORKS.Application.21")

          or 

          swApp = CType(System.Runtime.InteropServices.Marshal.GetActiveObject("SldWorks.Application"), SldWorks)

           

          are not opening the same session as when you open a session the normal way.

          Also the program stops with these lines; everything after these lines gets ignored. I have tried an If, Then, Else statement but the debugger does not come up with a message that there is something wrong with the code and it also ignores the rest of the code.

           

          When I run this code

           

          Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click

           

                  swApp = CreateObject("SLDWORKS.Application.21")

                  If swApp IsNot Nothing Then

                      swApp.Visible = True

                      MsgBox("Hello world!")

                  End If

           

              End Sub

           

          It does not ignore the message, that shows up, but is also not opening the same session as when you open a session the normal way.

          I prefer not to use the code of button3, there is not check whatsoever.

           

          I am under the impression that something is wrong with this bit ("SldWorks.Application")