A study card about variables in PDM API

Amen Jlili

Working with variables in PDM Professional API provides a unique set challenges. There are few methods and objects that get and set the values of variables each one with its conditions.

This can be very confusing sometimes.

In PDM API, the method SetVar and GetVar and all of their derivatives in newer versions of the IEdmEnumeratorVariableX (x from 5 to 10) interface have different conditions that you should be mindful of so you don’t shoot yourself in the foot when using them. Here’s a study card to help:

IEdmEnumeratorVariable5:GetVar

GetVar returns the value of a datacard variable. The variable has to be in the datacard of the file from which you pulled the IEdmEnumeratorVariable from, otherwise, GetVar will throw a nasty COMException. File should be cached locally.

IEdmEnumeratorVariable6:GetVarFromDb

GetVarFromDb returns the value of a variable. It pulls the value directly from the database. You don’t need the variable to be in a datacard (ie linked to a control in the datacard of the file). The value returned is always the latest. This is by far the quickest way to get a variable’s value if you don’t care about versions.

IEdmEnumeratorVariable7:GetVersionVars

GetVersionVar returns the values of datacard variables for a specified version of a file. Variables must be linked to a datacard. It has all the conditions of GetVar.

IEdmEnumeratorVariable5:SetVar

SetVar sets the value of a datacard variable if bOnlyIfPartOfCard is set to true. This means that if you set bOnlyIfPartOfCard to false, you can set any variables value, linked a datacard or not.
Affected file must be checked out unless the variable is version-free in which case you do not need to check the file out.
In the Visual Studio project properties, under the build tab, prefer 32-bits should be unchecked. This has been known to cause a COMException with the message “the file format plug-in cannot handle this file because a component is missing“. See this thread in SOLIDWORKS API forums.

IEdmEnumeratorVariable9:SetValueVariables

Same conditions as SetVar. The only difference is that this method can write the value to the file if the variable is mapped to a custom property. 

More great articles

Common must-know SOLIDWORKS EPDM add-ins errors for API enthusiasts

PDM administration tool Below is a compiled list of the most notoriously common errors that you may encounter while deploying…

Read Story
Arrow-up