QuitDoc shutting down SW?? is this right?

Discussion in 'SolidWorks' started by John MacIntyre, Sep 15, 2003.

  1. 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
    http://www.johnmacintyre.ca

    ----------------------------------------------------------------------------
    ------------------
    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 '<- this is where SW exits

    Exit Sub

    ERR_HANDLER:
    Debug.Print Err.Description

    End Sub
     
    John MacIntyre, Sep 15, 2003
    #1
  2. John,

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

    Mark
     
    Mark Mossberg, Sep 15, 2003
    #2
  3. Philippe Guglielmetti, Sep 15, 2003
    #3
  4. 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.
     
    Philippe Guglielmetti, Sep 15, 2003
    #4
  5. 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
    http://www.johnmacintyre.ca
     
    John MacIntyre, Sep 15, 2003
    #5
  6. John MacIntyre

    Heikki Leivo Guest

    John, if you use the Set oApp = New SldWorks.SldWorks line then you need
    to
    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-
     
    Heikki Leivo, Sep 15, 2003
    #6
  7. That worked great.

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

    Regards,
    John MacIntyre
    VC++ / VB / ASP / Database Developer
    http://www.johnmacintyre.ca
     
    John MacIntyre, Sep 15, 2003
    #7
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.