×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

SolidWorks and Command Prompt
4

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,

Chris Gervais
Application Engineeer
CADD Edge

RE: SolidWorks and Command Prompt

2
Chris,
      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

Sure, you can run SW with an initial macro from the command prompt..  I forget the exact syntax, but it's pretty simple.  You can't do much "manipulation" after that, but if your macro does what you need to do and then closes SW I don't see any reason that it wouldn't work.

RE: SolidWorks and Command Prompt

Here is the code I use to copy files to users C: drive then run a program then start SolidWorks.

CODE

Option Explicit

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

(OP)
Thanks People.  I appreciate the feedback.  Does anyone know where I might chase down the valid command line arguments for SolidWorks?  That's what is throwing me a curve as to whether or not the command line can be used, the lack of this kind of info in the help file (at least I couldn't find anything).

Regards,

Chris Gervais
Application Engineeer
CADD Edge

RE: SolidWorks and Command Prompt

I saw this posted somewhere a couple years ago. I have no idea if it works.

Quote:

You can specify a macro which should be executed with SolidWorks (a kind of autostart macro)
 with a commandline option "-m". Edit your shortcut to look like:

E:\Programme\sw2003\sldworks.exe -m "D:\daten\solidworks\macros\mm_24\Gen3DPointCloud.swp"

Ken

RE: SolidWorks and Command Prompt

(OP)
Bradley,

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

Chris,
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

(OP)
Thank you everyone.  I appreciate your sharing the information (and code - thanks Bradley).

Regards,

Chris Gervais
Application Engineeer
CADD Edge

RE: SolidWorks and Command Prompt

Thanks for the star Chris.

Bradley

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources