AnsweredAssumed Answered

Connecting to Solidworks instance without creating a new one

Question asked by J. R. on Oct 12, 2018
Latest reply on Oct 24, 2018 by Gertjan Van Dijk

Hi,

 

Making an addon for Solidworks (external executable, written in VB.NET), I always used to set swApp using = CreateObject("SldWorks.Application"). It worked, with a little issue of creating an invisible instance of Solidworks if it wasn't running when I ran my application. However, certain a person using my application with Solidworks Student Version has reported an error which indicates that my application cannot connect to his Solidworks instance. As I do not have access to a Student Version, I cannot check why, but I suspect the problem lies in this specific line. Can somebody advise me how should I set the swApp so it always connects to the running Solidworks instance, regardless of the version, and does not create a Solidworks ghost instance if my application was executed prior to running Solidworks?

 

I have tried the following lines, which I found in the official Solidworks API page, as well as various forum threads:

swApp = CreateObject("SldWorks.Application")  //didn't work with the Student Version, also creates a ghost instance of Solidworks;

swApp = Application.SldWorks //gives a warning "'SldWorks' is not a member of 'Application'

swApp = Activator.CreateInstance(Type.GetTypeFromProgID("SldWorks.Application")) //also creates a ghost instance of Solidworks;

swApp = GetObject(, "SldWorks.Application") //gives a "Cannot create ActiveX component" error;

swApp = CType(System.Runtime.InteropServices.Marshal.GetActiveObject("SldWorks.Application"), SldWorks) '= Application.SldWorks //gives a "Operation unavailable" error.

 

Can somebody point out the right way to do this, please?

Outcomes