Creates a second Solidworks instance in vba

Hello, I have to execute a code from excel and I would like it to execute this code on solidworks session that the user cannot see and especially that if a solidworks session is already open before it does not touch it and that the user can still work on it, the execution time of the code

 

at the moment I use this code to open Solidworks but it does not open a new instance

    Dim swApp As SldWorks.SldWorks
    Set swApp = CreateObject("SldWorks.Application")

 

Has anyone had the case where I am the only one with this need?

Hello

It is not necessarily advisable to open several Solidworks sessions on the same PC, this can lead to conflicts, starting with the message that appears when launching a 2nd session:

Kind regards

Hello

I use the standard PDM, it launches an instance of SW for the automatic creation of PDFs of validated drawings.
There may be some useful information on this side (See at Visiativ)

2 Likes

Hello

 

d.roger it has been several years now that we have all been running with several instances of Solidworks in view of the set that we have without causing any particular problem

 

Todesco , unfortunately, Visiativ keeps these secrets well^^

1 Like

Hello

If Solidworks is not started, then with the "CreateObject" function, you create a new object, otherwise you hang on to the object that is started. You should be able to use the "Shellexecute" function to start a new instance of the program.

Kind regards

Hello d.roger,

 

Indeed it's on this track that I'm getting stuck at the moment, no problem to start a new instance with shell but on the other hand to attach myself to this one and not to the first instance created it's another story  :/

Hello

This other story is already written but in C#, let's see if it's possible to translate all this into vba and that's where it might be funny, look at the validated answer which is here, and then for the message  about the log file when opening the second instance you have to look HERE. And, still in C#,  if you don't want to see the start of the second instance of Solidworks then you have to put "StartInfo.Arguments = "-m"" in the properties to pass to the "Start" method of the instance of the "Process" class.

I tested (in C#), except for the log file message, and it works pretty well ...

[EDIT]

After testing, the proposed solution for the log file message also works very well. So you just have from the 2 proposed links of the translation from C# to VBA to do and the modification to make the startup and the window of this new instance of Solidworks invisible. And of course, you have to think about freeing up all the resources and closing this instance of Solidworks at the end of your macro otherwise the process will continue to run.

[END EDIT]

Kind regards

3 Likes

Thank you for this complete feedback d.roger I just have to convert everything to VB and that I understand the C# by the way I will post the VB code once converted for those who might be interested

Hello

I have a SolidWorks macro (not from Excel) and I have the possibility to open another instance by going directly to the installation folder with:

Shell "C:\Program Files\SOLIDWORKS Corp\SOLIDWORKS\SLDWORKS.exe"

 

It's up to you to see if you can adapt it to your needs

 Hello rpicard

 

Indeed it works well, I had gone on this track at the beginning, the problem is that I couldn't attach myself to the newly created instance and not to the first instance.

 

But I keep :)

Hello

Yes, there are several ways to launch a second instance of Solidworks:

Dim objShell As Object
Set objShell = CreateObject("shell.application")
objShell.ShellExecute "C:\Program Files\SOLIDWORKS Corp\SOLIDWORKS\SLDWORKS.exe", "", "", "open", vbNormalFocus
Set objShell = Nothing

Or:

Shell "C:\Program Files\SOLIDWORKS Corp\SOLIDWORKS\SLDWORKS.exe", vbNormalFocus

But the primary concern is to attach and manage this second instance of Solidworks without disturbing the user who is working on the first instance of Solidworks. However, I see the second problem coming, which may be that if the user opens a Solidworks file by double-clicking on it, the file will open in this second instance of Solidworks instead of opening in the first instance.

Kind regards