When working with the SOLIDWORKS PDM API, it’s important to understand how the system handles state and caching. One frequently misunderstood property is IEdmFile5::IsLocked
. While it appears straightforward, it doesn’t behave like properties in reactive UI frameworks such as WPF, and this can lead to subtle but critical issues in automation and add-in development.
Understanding CLR Properties in the PDM API
In environments like WPF, dependency properties offer real-time synchronization with the underlying data model. Any change is automatically reflected in the property value. This is not the case with the PDM API.
Properties like IEdmFile5::IsLocked
are standard CLR properties. These properties do not auto-update when changes occur in the vault. Instead, they rely on cached data at the time the IEdmFile5
object was retrieved or last refreshed.
What This Means for Developers
IsLocked
will not reflect the actual current lock state of a file if that state has changed since the last time the file object was refreshed. This commonly occurs in scenarios such as:
- A file is locked or unlocked by another user
- A workflow transition unlocks a file
- An external operation changes the file status
In these cases, reading the IsLocked
property without refreshing the object will return outdated information.
Correct Usage
To ensure you’re working with current data, always call IEdmFile5::Refresh()
before accessing lock-related properties:
1 2 3 |
IEdmFile5 file = ...; file.Refresh(); bool isLocked = file.IsLocked; |
This forces the object to synchronize with the current state of the vault, ensuring IsLocked
reflects the latest status.
When to Use Refresh()
Besides IsLocked
, other properties that depend on current vault state also benefit from a refresh call:
CurrentState
CurrentVersion
In general, any time you suspect that external operations may have changed the state of a file, refreshing before reading is a safe and recommended approach.
Conclusion
The SOLIDWORKS PDM API does not use reactive or event-driven state tracking. It’s up to the developer to ensure that objects are up to date before relying on their state. For IEdmFile5::IsLocked
, a simple call to Refresh()
can prevent inconsistent behavior and reduce debugging time in complex workflows or automation scenarios.