UPDATE::
Turns out EnumDocuments2 does return them all; I had copied somecode from my previous project and overlooked a check I did forModelDoc2::Visible, effectively skipping the hidden documents,which is not what I wanted for this case. Fixed now but I willleave this post up for future reference.
I am after an efficient way to detect whether or not a SolidWorksfile is opened in SolidWorks (ie. locked to that SolidWorks so ifsomeone else wen't to open it it would say it is opened by anotheruser or whatever).
The problem is, the first check is whether or not the file islocked on the FileSystem at all, if it isn't then SW does not haveit open.
Then I try to check whether SolidWorks has the file open, and theonly way I know to do this so far is to call the ActivateDoc2function and see if it succeeds, if it does it was loaded into SWeven if it wasn't visible (for example a part from an assembly whenthe assembly is open). The problem with this is it is extremelyinefficient for determining if a file is loaded.
Using EnumDocuments2 also will not work as it only enumerates thedirect documents, not the ones loaded in the background as I amrunning out-of-process and even though the documentation statesthat EnumDocuments2 will only work with in-process dll's it doeswork out-of-process (but does not return the file references eventhough it states it should) * See note below.
Does anyone have a solution for this?
* Note for EnumDocuments2 *
Allows access to a documents enumeration. Can only be used inin-process DLLs.
The list of ModelDoc2 objects in the EnumDocuments2 object containsall open ModelDoc2 pointers, including ModelDoc2 objects opened asfile references (for example, from an assembly or drawing). You canuse ModelDoc2::Visible to determine if a particular document hasits own window and is visible to the user.
SolidworksApi macros
Turns out EnumDocuments2 does return them all; I had copied somecode from my previous project and overlooked a check I did forModelDoc2::Visible, effectively skipping the hidden documents,which is not what I wanted for this case. Fixed now but I willleave this post up for future reference.
I am after an efficient way to detect whether or not a SolidWorksfile is opened in SolidWorks (ie. locked to that SolidWorks so ifsomeone else wen't to open it it would say it is opened by anotheruser or whatever).
The problem is, the first check is whether or not the file islocked on the FileSystem at all, if it isn't then SW does not haveit open.
Then I try to check whether SolidWorks has the file open, and theonly way I know to do this so far is to call the ActivateDoc2function and see if it succeeds, if it does it was loaded into SWeven if it wasn't visible (for example a part from an assembly whenthe assembly is open). The problem with this is it is extremelyinefficient for determining if a file is loaded.
Using EnumDocuments2 also will not work as it only enumerates thedirect documents, not the ones loaded in the background as I amrunning out-of-process and even though the documentation statesthat EnumDocuments2 will only work with in-process dll's it doeswork out-of-process (but does not return the file references eventhough it states it should) * See note below.
Does anyone have a solution for this?
* Note for EnumDocuments2 *
Allows access to a documents enumeration. Can only be used inin-process DLLs.
The list of ModelDoc2 objects in the EnumDocuments2 object containsall open ModelDoc2 pointers, including ModelDoc2 objects opened asfile references (for example, from an assembly or drawing). You canuse ModelDoc2::Visible to determine if a particular document hasits own window and is visible to the user.
SolidworksApi macros