Using IEdmDictionary5 for Secure and Flexible Settings Storage in SOLIDWORKS PDM gives developers a reliable and safe way to store and retrieve configuration data inside the vault. The IEdmDictionary interface in the SOLIDWORKS PDM API allows you to manage settings that can be specific to an add-in or a user, while keeping everything protected through the vault’s login system. This approach removes the need for external files and ensures your data stays both organized and secure.
Advantages
- Secure Storage: Data is tied to the PDM vault and secured by the user’s login credentials.
- Add-In-Specific Settings: Use a unique key to isolate settings for your add-in.
- User-Specific Settings: Make settings unique to each user by appending the username to the key.
/// Get the vault object and dictionary
IEdmVault5 vault = /* Get your vault object */;
IEdmDictionary5 dictionary = vault.GetDictionary("MyAddInDictionary", true);
// Serialize your settings to a JSON string
string jsonSettings = JsonConvert.SerializeObject(new { Theme = "Dark", AutoSaveInterval = 10 });
// Use a key to identify the setting
string addInKey = "MyAddIn_Settings";
// Store the serialized JSON string in the dictionary
dictionary.StringSetAt(addInKey, jsonSettings);
Retrieving Settings
To retrieve the stored settings, use the StringGetAt method:
// Retrieve the JSON string from the dictionary
string retrievedJsonSettings;
dictionary.StringGetAt(addInKey, out retrievedJsonSettings)
// Deserialize the JSON string back into an object
var settings = JsonConvert.DeserializeObject<dynamic>(retrievedJsonSettings);
User-Specific Settings
You can create user-specific settings by appending the username to the dictionary key:
string userSpecificKey = $"MyAddIn_Settings_{vault.CurrentUser.Name}";
dictionary.StringSetAt(userSpecificKey, jsonSettings);
Best Practices
- Use Descriptive Keys: Clearly define your dictionary keys to avoid conflicts.
- Validate Data: Ensure your JSON strings are valid before storing them.
- Avoid Excessive Use: Reserve the dictionary store for data that needs to be secure or specific to the PDM environment.
- Secure Storage: Data is tied to the PDM vault and secured by the user’s login credentials.
- Add-In-Specific Settings: Use a unique key to isolate settings for your add-in.
- User-Specific Settings: Make settings unique to each user by appending the username to the key.
