2 Replies Latest reply on Sep 12, 2017 12:19 PM by Michael Caulton

    API - Close active doc and don't save

    Michael Caulton

      I have an assembly open that I need to activate several of the parts, then hide some stuff int he part, then save as JPG and close the part and not save changes.


      My current method is to use:

      • swApp.IGetOpenDocumentByName2(Name) to get the new part model data from its name in the assmebly
      • swApp.ActivateDoc2(swModel.GetTitle, True, Nothing) to activate the doc
      • swApp.QuitDoc(swModel.GetTitle) or swApp.CloseDoc(swModel.GetTitle) to close the doc that was activated


      The problem I have is that a "Save Modified Documents" dialog sometime shows. Image attached.


      The dialog does not show for every part.


      Is there a way make this not show and for the changes to be discarded? ie activate read only or closedoc and not save

        • Re: API - Close active doc and don't save
          Nilesh Patel

          Hi Michael,


          You don't have to open the assembly document to open its parts and sub assemblies. You can use ISldWorks::OpenDoc6 or OpenDoc7 method to open all documents if you already know the path of them. In this case you can set the option to open the parts and sub assemblies in read only mode.


          If you have to open the final assembly (may be to select parts and sub assemblies from it), then you can use ISldWorks::ActivateDoc3 method rather than ISldWorks::IGetOpenDocumentByName2. Below is the screenshot from the remarks for 'IGetOpenDocumentByName2' method which indicates that if documents are not opened in its own window then this method may not work as expected.

          Once you obtain IModelDoc2 object for each part or assembly, you can set the ready only status by using IModelDoc2::SetReadOnly to true. Do whatever you want to do and the close the document by using QuitDoc or CloseDoc.


          You can set the option to discard the changes to read only documents as shown below:

          You may have to close final assembly document to discard change to parts and sub assemblies you worked on.


          Good luck.