QuitDoc shutting down SW?? is this right?

Sep 15, 2003 8 Replies

Hi,



I am having a problem keeping the SW application open.



My problem is isolated to the following VB function. I open a part file and everything is fine .. but when I close the file, SolidWorks exits!



I want to open & close files repeatedly, but can't seem to keep SW open. Can anybody point out what I am doing wrong? I am new to SW and expect I may be doing something stupid.



Thanks, John MacIntyre VC++ / VB / ASP / Database Developer

formatting link



----------------------------------------------------------------------------



------------------ Option Explicit



Sub Main() On Error GoTo ERR_HANDLER Const swDocPART = 1 Const sFileName = "MyTestPart.SLDPRT" Dim oApp As SldWorks.SldWorks Dim oDoc As SldWorks.ModelDoc2



Set oApp = New SldWorks.SldWorks oApp.Visible = True



Set oDoc = oApp.OpenDoc(sFileName, swDocPART) Debug.Print "Properties for " & sFileName Debug.Print vbTab & "Title :" & oDoc.SummaryInfo(0) Debug.Print vbTab & "Subject :" & oDoc.SummaryInfo(1) Debug.Print vbTab & "Author :" & oDoc.SummaryInfo(2)



Set oDoc = Nothing oApp.QuitDoc sFileName '


John,

That's a weird one, sounds like a bad install. Did you have anti-virus running when you installed SW ?

Mark

Just made this:

formatting link
the challenge was to make a "twisted loft" between 2 profiles. Guide curves don't allow this. Is there a need for an add-in here ?

read the remark in apihelp.chm: " If you are closing the only document in the SolidWorks session and this SolidWorks session is a background session, then calling SldWorks::CloseDoc or this method results in the SolidWorks session being closed. " a "background session" is a SW session that was started by opening a SW document rather that explicitely starting SW.

Just made this:

formatting link
the challenge was to make a "twisted loft" between 2 profiles. Guide curves don't allow this. Is there a need for an add-in here ?

Thanks Philippe,

But isn't my example explicitly starting SW? Set oApp = New SldWorks.SldWorks

If not, how would I explicitly open it in VB?

Thanks in advance, John MacIntyre VC++ / VB / ASP / Database Developer

formatting link

SldWorks::CloseDoc

John, if you use the Set oApp = New SldWorks.SldWorks line then you need to have a dummy document that doesn't get closed as Philippe mentioned. If you don't want to do this, you can use the CreateObject() method.

Best Regards,

IIRC, there is a bit easier way to prohibit SW from closing...

Set swApp = New SldWorks.SldWorks swApp.UserControl = True

Refer to API help, swApp::UserControl

Hope this helps!

-h-

That worked great.

Thanks a lot for the help everyone. ... I really appreciate it.

Regards, John MacIntyre VC++ / VB / ASP / Database Developer

formatting link

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required