API: Close all open documents

Discussion in 'SolidWorks' started by Evan T. Basalik, Jun 18, 2004.

  1. I had to close all the open documents in an application I was writing. I
    ended up having to work this out, so thought I would share it. It's VB.NET,
    but could be easily modified to work in a macro or VB6.

    Private Function CloseAllOpenSWFiles()

    'close all open docs

    Dim OpenDocs As SldWorks.EnumDocuments2

    Dim OpenDoc As SldWorks.ModelDoc2

    OpenDocs = swApp.EnumDocuments2()

    OpenDoc = swApp.ActiveDoc

    While Not OpenDoc Is Nothing

    Try

    OpenDoc.Save3(SwConst.swSaveAsOptions_e.swSaveAsOptions_SaveReferenced, 0,
    0)

    Debug.WriteLine("Closing " & OpenDoc.GetPathName)

    swApp.CloseDoc(OpenDoc.GetPathName)

    OpenDocs.Next(1, OpenDoc, 0)

    Catch ex As Exception

    'if errors out, then all documents have been closed

    OpenDoc = Nothing

    End Try

    End While

    End Function
     
    Evan T. Basalik, Jun 18, 2004
    #1
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.