Does the SW API fire an event when a document's read-only state changed? I'm looking to capture when a file is checked-out via the PDM task pane in SW. Figured I'd ask here quickly before I roll my own.
You can check if its read only using the .isopenreadonly method. 2017 SOLIDWORKS API Help - IsOpenedReadOnly Method (IModelDoc2)
Thanks, but I would like to be notified when the state changes.
Have you looked into the SOLIDWORKS PDM Add-in. I'm not sure it has an API of some sort...
I'm not sure checking read-only attribute is good idea. Although, you can monitor that attribute by using a FileSystemWatcher, please don't. The read-only attribute can be changed by a third application or even by the user goofing around and that will cause your application to fire inadvertently.
The only you can do this is if you monitored the field [Documents].[dbo].[LockDate] in your PDM's vault database. This field accepts null. Whenever this field changes, it will receive the date and time of when the file was locked ie checked out. When the file is checked back into the vault, the field receives null.
Now, you'll need to a sql access for this and you need to create sql dependency object to receive notifications when changes in db occurs. Here's a good Stackoverflow example: https://stackoverflow.com/questions/25348565/refresh-application-automatically-when-data-changed-in-sql-server
You'll also need to get the document ID via it's local path. That should be straightforward. Just connect to the vault and Use EdmVault5.GetFileFromPath
This is a SW add-in, and I am not able to introduce a PDM add-in to notify the SW add-in. I thought about that but it's not feasible in my scenario.
I was thinking about using a FileSystemWatcher and that may be the only way to go. I'm not worried about it being triggered inadvertently, as my logic would handle that.
Thanks for the reply!
Who said anything about PDM addins? Everything can be accomplished if you have access to the PDM vault database. It's all going to be SQL except for getting the document ID which you would need to login to the vault for. You can do all of that from your solidworks add-in.
I understand, but I would be polling the DB for changes. If I had a PDM add-in I could be notified via the Unlock hook. The SW add-in I created will be deloyed to dozens of clients, so I don't think the client would appreciate having to a) store credentials somewhere, b) otherwise use a config, and c) having thousands of reads against the DB for changing file states.
I believe when file is checked-out an checked-in SOLIDWORKS will unload and reload the document as as far as I known it is not possible to change the sate of the opened stream (i.e. if stream is opened read-write it cannot be changed to read-only). Have you tried this event: DPartDocEvents_FileReloadNotifyEventHandler Delegate?
I did try the FileReload event but it wasn't fired. I don't think the file is reloaded, I think the PDM add-in asks SW to release the lock.
My experience with the file reload event is that it is (confusingly) only fired when actually going to through the File->Reload option. Maybe you could just check for a regular iSwApp.DocumentLoadNotify2 and check if it is the correct file
Retrieving data ...