SolidWorks and Command Prompt
SolidWorks and Command Prompt
(OP)
Hi All,
I had someone ask a question today regarding whether or not SolidWorks can be invoked and run from the command prompt along with a macro. They want to run this from within an application (which is essentially a batch file) that consists of a number of other programs run in sequence (including SW and the macro in question).
My question is this: is it possible to invoke and manipulate SW from the command prompt? Personally I think the answer is "no" but I would appreciate a gut check on this to be absolutely certain. There doesn't appear to be anything in the SW help files to dispute this.
I think that they can accomplish their aim by writing a standalone executable (which instantiates SW and performs whatever sequence of actions is required) stored on the local system and invoking that in the batch file. Any thoughts on whether this is achievable or better suggestions would be appreciated.
Regards,
I had someone ask a question today regarding whether or not SolidWorks can be invoked and run from the command prompt along with a macro. They want to run this from within an application (which is essentially a batch file) that consists of a number of other programs run in sequence (including SW and the macro in question).
My question is this: is it possible to invoke and manipulate SW from the command prompt? Personally I think the answer is "no" but I would appreciate a gut check on this to be absolutely certain. There doesn't appear to be anything in the SW help files to dispute this.
I think that they can accomplish their aim by writing a standalone executable (which instantiates SW and performs whatever sequence of actions is required) stored on the local system and invoking that in the batch file. Any thoughts on whether this is achievable or better suggestions would be appreciated.
Regards,
Chris Gervais
Application Engineeer
CADD Edge






RE: SolidWorks and Command Prompt
My guess is yes. I left mouse clicked on START button and in the Run… I typed in C:\Program Files\SolidWorks\Executables\ProgramName.exe
It ran just fine.
Bradley
RE: SolidWorks and Command Prompt
RE: SolidWorks and Command Prompt
CODE
Const SYNCHRONIZE = &H100000
Const INFINITE = &HFFFF 'Wait forever
Const WAIT_OBJECT_0 = 0 'The state of the specified object is signaled.
Const WAIT_TIMEOUT = &H102 'The time-out interval elapsed, and the
'object’s state is nonsignaled.
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Sub Form_Load()
Dim CopySolidWorksMacros As String
If Dir$("C:\Program Files\SolidWorks\Executables") = "" Then
On Error Resume Next
MkDir "C:\Program Files\SolidWorks\Executables"
End If
FileCopy "M:\Applications\SolidWorks\Executables\CopyFile.exe", _
"C:\Program Files\SolidWorks\Executables\CopyFile.exe" ' To:
CopySolidWorksMacros = Shell("C:\Program Files\SolidWorks\Executables\CopyFile.exe", 1) ' Run Copy Files program & SolidWorks.
Dim StartSolidWorks As String
On Error Resume Next ' if user leaves text box to soon, then they will be continued to next
StartSolidWorks = Shell("C:\Program Files\SolidWorks\sldworks.exe", 1) ' Run Copy Files program & SolidWorks.
Call cmdExit_Click
End Sub
Private Sub cmdExit_Click()
Unload Me
End
End Sub
Bradley
RE: SolidWorks and Command Prompt
Regards,
Chris Gervais
Application Engineeer
CADD Edge
RE: SolidWorks and Command Prompt
Ken
RE: SolidWorks and Command Prompt
http:
It's down toward the end of this article.
RE: SolidWorks and Command Prompt
I am looking at your code and think I understand what you're doing but just to be clear please tell me if this is how it works (in general):
- This code is from a standalone executable program
- It searches for/creates the C:\Program Files\SolidWorks\Executables directory
- "CopyFile.exe" is copied from the network to the local folder referenced in the previous step
- "CopyFile.exe" is executed via the Shell command
- SolidWorks is launched via the Shell command
Now that it is apparent that it is possible to accomplish what I initially asked about I'm trying to get a better feel of my options to determine which way to go.
Thanks,
Chris Gervais
Application Engineeer
CADD Edge
RE: SolidWorks and Command Prompt
Yes, everything you said is correct. To take it one more step, I put in my SolidWorks icon for target the following: M:\Applications\SolidWorks\Executables\StartSolidWorks.exe “M” is our mapped network drive. Of course you will have to change the symbol back to the SolidWorks logo, because this icon is really not the SolidWorks shortcut anymore.
Bradley
RE: SolidWorks and Command Prompt
Regards,
Chris Gervais
Application Engineeer
CADD Edge
RE: SolidWorks and Command Prompt
Bradley