In my everyday work, I spend a lot of time waiting on SolidWorks to finish a task. The SolidWorks task scheduler is able to remove some of these burdens by allowing them to be run overnight. The great thing about the task scheduler is that it allows me to select folders or groups of files and runs the task in a separate SolidWorks instance for each file it finds. It also has a timeout for each file to complete its task. This means it can keep churning through all of the files and recover from a problem with one of the files (SolidWorks 2008 is notoriously unstable).
The problem is that the number of tasks available is limited. There is the Custom Task which allows you to run a custom program or macro, but for some reason removes the file selection capability. It is for this reason that I set out to recreate the functionality of the task scheduler, but with the ability to run any macro (or multiple macros) in separate instances of SolidWorks for entire groups of files. I call it SolidWorksBatchRunner.
Let me start with the usage statement for SolidWorksBatchRunner and continue with some examples of its functionality.
Usage: SolidWorksBatchRunner /m:MacroFile[|MacroModule[|MacroProcedure]] ..
[/l:LogFile] [/n] [/r] [/s [/q]] [/t:Timeout] FileSearch ..
Runs the specified macros on the files found from the specified file
searches.
/m:MacroFile|MacroModule|MacroProcedure
The macro(s) to run on the specified files. MacroModule
defaults to MacroFile - extension + 1. MacroProcedure
defaults to main
/l:LogFile
The log file to use. Defaults to the current date/time:
yyy-MM-dd HH-mm-ss.log.
/n
Specifies that each macro should be ran in a new SolidWorks
instance.
/q
Specifies that the files should be rebuilt after all macros
have run. Cannot be used without /s switch.
/r
Searches will also include subdirectories.
/s
Specifies that the files should be saved after all macros
have run.
/t
The time, in seconds, each macro is given to complete its
task. The default is 300 seconds.
/?
/h
/help
Prints this usage statement and exits.
I have included several options that I have found useful to a task scheduler application. So lets say you want to take a group of drawings and run your “DXFExport” macro on all the files. We don't need to save the SolidWorks files afterward because we didn't change anything. A command to do this could look like:
SolidWorksBatchRunner /m:"C:\My SW Macro Folder\DXFExport.swp" "C:\My Drawings Folder\*.SLDDRW"
A couple of assumptions have been made.
The previous example shows how to run one macro on one file search, but it is possible to do multiple of each. We can also specify the name of a log file to create.
SolidWorksBatchRunner ^ /m:"C:\My SW Macro Folder\Macro1.swp|Macro11|main" ^ /m:"C:\My SW Macro Folder\Macro1.swp|Macro11|alternate" ^ /m:"C:\My SW Macro Folder\Macro2.swp" ^ /s /q /r ^ /l:"My Log File Name.log" ^ "C:\My Drawings Folder\Folder 1\*.SLDDRW" ^ "C:\My Drawings Folder\Folder 2\*.SLDDRW" ^ "C:\My Drawings Folder\Folder 3\Start*End.SLDDRW"
With this example:
I have uploaded a zipped up Visual Studio Express project file used to make this program as well as a zipped up file of the executable and the SolidWorks libraries that it uses. The code is released under the ISC License. I have only tested it with SolidWorks 2008 SP3.1 and .NET framework 3.5 installed. If anyone runs into any problems or has a suggestion, let me know by posting a comment to this post.
Discussion