Umm, why would you? Why do you care? Will you wish to treat the document differently if it was open already? If not, just ignore the warning and go on your merry way.
I am trying to understand why CloseDoc doesn't seem to be unloading from memory a file previously opened by OpenDoc6. I would expect that CloseDoc closes the file and unloads the file from memory but I am getting back the warning the second time I try to open the file.
This is the scenario:
0. Settings->Performance: Automatically load components lightweight (so my understanding of this is it will only load in memory the assembly not the parts inside the assembly)
1. Open Assembly "C:\Users\Public\Documents\SOLIDWORKS\SOLIDWORKS 2018\samples\tutorial\advdrawings\blade shaft.sldasm" in Solidworks
// File path for part that is in the assembly
string Filename = "C:\\Users\\Public\\Documents\\SOLIDWORKS\\SOLIDWORKS 2018\\samples\\tutorial\\advdrawings\\drive shaft.sldprt";
// Open part that is inside the assembly => ALL OK no warnings
mSolidWorksApplication.OpenDoc6(Filename(int)swDocumentTypes_e.swDocPART(int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);
// Close the part
// Open again the same part => I get warnings: swFileLoadWarning_AlreadyOpen
mSolidWorksApplication.OpenDoc6(Filename, (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);
You can't unload a document from memory using CloseDoc if it is still open based on being referenced by another document. The window may close, but it's still loaded into memory because it's being used in the assembly. This is the same behavior as the user interface. Try it. On a fresh session, open an assembly all lightweight. Check the number of open files. Should be 1. Now open one of the components in its own window. Check and find 2 open files. Now close the window for the component. Still 2 open files because that part became loaded into memory when you opened it in its own window. Now set that component back to lightweight from the assembly. Check open file qty - it's back to 1.
@Josh that is exactly what I am trying looking what GetDocuments returned.
1. I open an assembly all lightweight and call GetDocuments which returns one so this means that its parts it will still be loaded in memory not only the assembly as I thought?
2. I open the assembly all lightweight then I close the assembly and then I open/close the part and open again the part no warnings so the part wasn't load into memory this time.
So the only way to release the parts loaded to memory when opening an assembly no matter if it was lightweight or not is closing the assembly right?
Also GetDocuments is only giving open files, is it any method where we can see the documents loaded in memory?
Before I respond, I'm gonna give you some time to re-read and attempt to understand what I posted here and in the other thread.
@Josh thanks for the replies, checked both threads and the other was making sense although @Deepak said that when open an assembly in lightweight the parts are loaded in memory so it made me wonder how this could be and if GetDocuments only was returning opening documents instead of loaded documents in memory as if opening and loading a document in memory are not the same thing and we can use other method to see the actual loaded memory documents. But from the experiments when I open assembly without enabling lightweight GetDocuments return also the parts, so it must be taken into account files loaded in memory.
So in summary to unload the memory of the parts I can close the assembly and then open/close the parts or keep the assembly open but once I have opened a part close won't release it needs to be reverted to lightweight which I guess there is another API method to do this.
Carmen Lopera wrote:
@Josh thanks for the replies, checked both threads and the other was making sense although @Deepak said that when open an assembly in lightweight the parts are loaded in memory.
I was wrong in stating that it load them into memory when opened as lightweight. Thanks Josh for the correction.