2 Replies Latest reply: Jan 31, 2013 4:52 PM by Artem Taturevych

    Close Part and Assembly but not Drawing

    Steven Smith

      I'm looking for a line of vb code that will close the active part or assembly file but keep the active drawing file open.

      Can anybody help?

        • Re: Close Part and Assembly but not Drawing
          Keith Rice

          Steven,

           

          There is no line of code that will do this exact task. Instead you need to use ISldWorks::CloseDoc to close the particular documents you want. If you are trying to close only documents with a particular name, note that you should include the file extension in the name argument, otherwise this method may close the wrong document if multiple documents have the same name (e.g., "123.SLDPRT" and "123.SLDASM").

           

          To get the names of the open documents, use ISldWorks::GetDocuments. Here is some code that will close all non-drawing documents:

           

          ===========

           

          Dim swApp As SldWorks.SldWorks

          Dim swModel As SldWorks.ModelDoc2

          Dim vOpenDocs As Variant

          Dim i As Integer

           

          Sub main()

              Set swApp = Application.SldWorks

              Set swModel = swApp.ActiveDoc

             

              vOpenDocs = swApp.GetDocuments

              For i = 0 To UBound(vOpenDocs)

                  Set swModel = vOpenDocs(i)

                  If swModel.GetType <> swDocDRAWING Then swApp.CloseDoc swModel.GetTitle

              Next i

          End Sub

           

          ===========

           

          Keith

          Video Tutorials for the SolidWorks API

          • Re: Close Part and Assembly but not Drawing
            Artem Taturevych

            Dim swApp As SldWorks.SldWorks

            Dim swModel As SldWorks.ModelDoc2

             

            Sub main()

             

                Set swApp = Application.SldWorks

               

                Set swModel = swApp.ActiveDoc

               

                If swModel.GetType <> swDocumentTypes_e.swDocDRAWING Then

                    swApp.CloseDoc swModel.GetTitle

                End If

               

            End Sub

            __________________________

            Regards,

            Artem Taturevych

            Application Engineer at Intercad

            http://intercad.com.au/

            Tel: +61 2 9454 4444