My favorites | Sign in
Project Logo
                
Search
for
Updated Jul 02, 2009 by ganeshra...@gmail.com
Labels: Featured, solidworks
SwxBatch  
How to run SolidWorks in batch mode using SolidWorks API + COM

Introduction

The following text was originally posted on my blog at http://ossandcad.blogspot.com/2008/04/batch-mode-solidworks.html,

Details

I saw a post on Google Groups where a user had posted a question (2 years ago) asking how one could open SolidWorks silently viz. no GUI and use SolidWorks APIs to open a part but there was no answer that I could find right of.

In the same vein as my previous post titled "Batch mode Pro/Engineer" I tried to create a similar workspace for SolidWorks that executes SolidWorks with no GUI but still uses the SolidWorks API to load and query parts or assemblies. Fortunately SolidWorks API makes it much easier to do this as compared to Pro/Toolkit. After a little experimentation I came up with the following solution. The solution was created in Visual Studio 2005 using Visual C++. Click on the following zip file to download the solution.

Setup of Solution

Simply create a new "Win32 Console Application" project in Visual Studio 2005.

Edit the project's properties and add the following directory to the "Additional Include Directories" under "Configuration Properties"->C/C++->General:

"c:\program files\solidworks\samples\appcomm\win32\"

You should have a "cpp" file named swbatch.cpp (or something similar depending on the name you selected for the console application). Open that file and add the following code to it above the main() (or tmain()) function.

#include "iostream"
#include "objbase.h"
#include "atlbase.h"

//Import the SolidWorks type library
#import "C:\Program Files\SolidWorks\sldworks.tlb" raw_interfaces_only, raw_native_types, no_namespace, named_guids
//Import the SolidWorks constant type library
#import "C:\Program Files\SolidWorks\swconst.tlb" raw_interfaces_only, raw_native_types, no_namespace, named_guids 

Then modify your main() (or tmain()) function to look like the source code included in the zip file. I apologize for not posting the code directly into the body of this post, but Blogger was messing up the formatting.

Make the following changes to the code in main():

Build the solution and execute it. The console application will startup and silently load SolidWorks. If you have Windows Task Manager open then you will see SLDWORKS.exe running. If the SLDPRT is found in the right location, then the code above reads the SLDPRT and throws a MessageBox with the name of the first feature of the SLDPRT, which in this case is "Annotations". After the program exits, SolidWorks exits too.

Note: Please keep in mind the following points about the code in main() in the zip file:


Comment by jesse.seger, Aug 10, 2009

Document Mananger API has many methods without opening SolidWorks?. You just have to ask SolidWorks? Corp for a KEY. It's free.

Comment by ganeshra...@gmail.com, Aug 10, 2009

Thanks jesse.seger for your comment. On a cursory look at the Document Manager API help file, I do not see comprehensive support similar to that provided by SolidWorks?' VC++/.NET API SDK e.g. create features in 3D models etc. If I am mistaken any pointers to relevant documentation would be most welcome.


Sign in to add a comment
Hosted by Google Code