Open Document Code

I am a beginner with VB.net and Solid Works and I need anexampleof opening a document and printing it to the defaultprinter.
I can call SW and have it open but the document does not openjustthe app. Here is what I have so far:

Dim swApp As SldWorks.SldWorks
foundFile = "C:\\In\\6.slddrw"
swApp = New SldWorks.SldWorks
swApp.OpenDoc(foundFile, 0)
swApp.Visible = True

I have a stop here to look at the application for the file:

swApp.CloseDoc(foundFile)

I have tried OpenDoc6 but I do not understand what theargumentswhere all about. Do I need to dim them and set the value.
Any help would be wonderful.

Thanks,
Jim
SolidworksApi macros
Comments 3
SF
SF 2007-02-03
Jim,

Seeing that you are a beginner, I would recommend using the SW VBAmacro editor for awhile and studying the examples in the API help(the examples work better in VBA). There are examples for many ofthe calls and they can be invaluable for learning SolidWorks APIprogramming. In fact there is a very simple example for usingOpenDoc6. Okay enough of my preaching. First I am also new toVB.Net, however unless you have turned off Option Explicit or amnot showing all of your code, do you not get an error because youhave not declared the foundFile variable? But that aside, thereason your code does not work is because you used the wrong valuefor the second parameter in the OpenDoc method. If you look inhelp, the second parameter is for the file type as defined byswDocumentTypes_e. Look for this in API help; you will find thereare four possible values: swDocNONE, swDocPART, swDocASSEMBLY andswDocDRAWING. If you set your project references to include theSolidWorks 2007 (or whatever version you are using) Constant TypeLibrary, you can use the object browser to see that the values are0, 1,2,3 respectively. This means that for a drawing the secondvalue should be set to swDocDrawing or 3. You have it set to 0 orswDocNone. The call will not work when the two parameters aremisnmatched.

Yes for a beginner at both VB and SolidWorks, the OpenDoc6 can beimposing. I have been working with the API for 6 years and I stillhave trouble understanding exactly what all the parameters do inmany of the calls. I have found the best thing to do is look atexamples (use the search tab), experiment (what is the worst thatcan happen?) and of course ask questions out here. You can alsocontact API help; they are alittle slow at getting back to you attimes but they are an invaluable resource if you cannot find whatyou are looking for or something will just not work. There I goagain preaching. Sorry. If you have a specific question about theOpenDoc6 method, please post your question. Either myself orsomeone else will answer.

One last thought, another resource can be found in the SolidWorks3D CAD products forum athttp://www.eng-tips.com/. Theyhave many knowledgeable (means they know a lot more than I do)people that will be glad to help you.

SA
SF
SF 2007-02-04
Thanks for the quick reply SolidAir. Your answer was right oninthe fact that I had the wrong value for openDoc. Once Ichangedthis, everything is working perfect. Thanks for theresources also.They will be very helpful.
Again thanks.
Jim
SF
SF 2007-02-05
As a side note to the SW VBA macro editor. There may be timeswhen the SW VBA recorder reports a call ot certain method that isno longer valid or obsolete. This may leave you scratching yourhead trying to figure out why there is no help found in the APIdocumentation for a particular method. The API help should also beviewed with caution. I have found errors relating to SW APIdocumentation in the past. Bottom line the API help file is not100% reliable.