Today I made an example of updating the file variables. It took a while to get it out. Paste the code.
File before variable change
Create a class library in VS and add the following method
''' <Summary> ''' obtain the file ''' </summary> ''' <param name = "files"> all added files </param>'' '<param name = "SetName"> BOM entry name </param> ''' <remarks> </remarks> Public Sub GetFiles (ByRef files () as EdmListFile, ByVal SetName As String) lst. createListEx (SetName, 0, cols) 'calls the method in IEdmBatchListing2 and adds the file lst. getFiles (files) 'Get all files in 'end Sub ''' <summary> ''' Update file information''' </summary> ''' <param name = "vName"> variable name </param> ''' <param name = "value"> variable value </param> ''' <remarks> </remarks> Public Sub BatchUpdateFileVariable (ByVal vName As String, byVal value As Object) Dim varMgr As IEdmVariableMgr5 'defines the variable Object varMgr = vault Dim var As IEdmVariable5 var = varMgr. getVariable (vName) 'gets the Dim Upate As IEdmBatchUpdate2 variable corresponding to vName, and defines the update object Upate = vault. createUtility (EdmUtility. edmUtil_BatchUpdate) Dim files () As EdmListFile = Nothing GetFiles (files, "") 'get the file For Each efile As EdmListFile In files Dim file As IEdmFile8 = vault. getObject (EdmObjectType. edmObject_File, efile. mlFileID) If Not file. isLocked Then file. lockFile (efile. mlFolderID, 0) End If Upate. setVar (efile. mlFileID, var. ID, value, "", 1) 'Add the content to be updated Next Dim Errors () As EdmBatchError2 = Nothing Dim errcount As Integer = Upate. commitUpdate (Errors) 'submit and catch Errors If errcount> 0 Then MsgBox ("error") Else MsgBox ("updated successfully") End If End Sub
Then create a form. before changing the variable, read the file (written in SolidWorks EPDM secondary development entry (1) and add a button.
The button code is as follows:
Try Finfo. batchUpdateFileVariable ("Project No.", "A395") 'calls the background update function Finfo. batchUpdateFileVariable ("project name", "SolidWorks") Catch ex As Exception MsgBox (ex. message) End Try the changed file variable below