Bulk add variables - SOLIDWORK PDM Pro Vault
If you have ever taken the SOLIDWORKS PDM Professional administration class, you know that in the very first lesson, SOLIDWORKS recommends that you make a nice, little chart pre-planning your variables. You are supposed to make a list of variables, the variable types and some notes on how that variable should be used. This certainly is a good idea. Good planning makes a good vault.
You’re proud of your list. Lots of variables. Lots of time putting it all together… But now what? How do you get all of these variables into PDM? Should you do it one at a time? No way, not you, manual input is for suckers. During the class you remember seeing the “Import” button in the lower left corner of the Edit Variables dialog box. Maybe you could bulk add variables into SOLIDWORKS PDM with that! You smile to yourself because you know how clever you are.
You click the Import button. The dialog asks you for a *.cvr file. You’ve never seen anything in the help file describing the definition of a .cvr file. The Administration Guide? Nothing there either. Your favorite search engine doesn’t reveal anything [except this post that you are now reading]. Turns out, that if you want to use a .cvr file you are going to need a time machine. A .cvr file is a legacy file type that was used before the current .cex files were invented. Sometime back when PDM was called Conisio -and not even the latest version of Conisio, but version 5.3. Version 5.3 was released near the year 2003. Since your DeLorean is in the shop, this option is useless to you. (…and probably everyone else!)
Is there a Solution? How can I add these variables in bulk?
Turns out, your only solution is to use PDM’s programming interface. You won’t need anything fancy, just Excel and its macros. [Excel macros shouldn’t be looked down on. They are great for little batch jobs like this!]
The intent of this article isn’t to teach you how to write an API program, there are many other avenues for learning API. I just want to give you a little starter program -something you can clip into your own application.
First start with an Excel worksheet.
Now loop through all of the variables, collecting their information. Then with the IEdmVariableMgr6 object, add the variables.
The variable manager is pretty smart too. It can also update variable properties. If the variable name already exists, the variable manager will update the variable to your selected attributes.
Although this code doesn’t demonstrate it, the Variable Manager can also define your property mappings too. The EdmAttributeData attribute collection lets you assign a block and attribute names along with the extensions of that mapping. You can do it all with the variable manager and never have to open that “Edit Variable” dialog box again!
Option Explicit Const cintStartRow As Integer = 3 'row of the first variable Const cintVarNameColumn As Integer = 1 Const cintVarTypeColumn As Integer = 2 Const cintMandatoryColumn As Integer = 3 Const cintVersionFreeColumn As Integer = 4 Const cintUniqueColumn As Integer = 5 Sub main() Dim objVault As IEdmVault10 Set objVault = New EdmVault5 objVault.LoginAuto Cells(1, 2), 0 'name of the vault read from cell B1 Dim lngLastRow As Long lngLastRow = Cells(Rows.Count, cintVarNameColumn).End(xlUp).Row 'find the last row (assumes you didn't skip any rows) Dim objVariableManager As IEdmVariableMgr6 Set objVariableManager = objVault.CreateUtility(EdmUtility.EdmUtil_VariableMgr) Dim aVariableData() As EdmVariableData ReDim Preserve aVariableData(lngLastRow - cintStartRow) Dim intVariableFlags As Integer Dim intRow As Integer Dim intCount As Integer For intRow = cintStartRow To lngLastRow 'loop through all variables intVariableFlags = 0 'reset intCount = intRow - cintStartRow 'zero based array aVariableData(intCount).mbsVariableName = Cells(intRow, cintVarNameColumn) 'variable name Select Case Cells(intRow, cintVarTypeColumn) 'Variable type Case "Text" aVariableData(intCount).meType = EdmVariableType.EdmVarType_Text Case "Bool" aVariableData(intCount).meType = EdmVariableType.EdmVarType_Bool Case "Int" aVariableData(intCount).meType = EdmVariableType.EdmVarType_Int Case "Date" aVariableData(intCount).meType = EdmVariableType.EdmVarType_Date Case "Float" aVariableData(intCount).meType = EdmVariableType.EdmVarType_Float End Select 'other variable properties If Cells(intRow, cintMandatoryColumn) = "Yes" Then intVariableFlags = EdmVariableFlags.EdmVar_Mandatory If Cells(intRow, cintVersionFreeColumn) = "All Versions" Then intVariableFlags = intVariableFlags + EdmVariableFlags.EdmVar_VerFreeUpdateAll If Cells(intRow, cintVersionFreeColumn) = "Latest Version" Then intVariableFlags = intVariableFlags + EdmVariableFlags.EdmVar_VerFreeUpdateLatest If Cells(intRow, cintUniqueColumn) = "Yes" Then intVariableFlags = intVariableFlags + EdmVariableFlags.EdmVar_Unique aVariableData(intCount).mlEdmVariableFlags = intVariableFlags 'define the variable properties Next intRow objVariableManager.AddVariables aVariableData 'add the variables Set objVariableManager = Nothing End Sub