Site icon BLUE BYTE SYSTEMS INC.

SOLIDWORKS PDM API Tip: Using IEdmDictionary5 for Secure and Flexible Settings Storage in SOLIDWORKS PDM

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

/// 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

Exit mobile version