By Wayne Brill
IExplorerUtil.UpdateFileProperties() can be used to update mapped properties such as Inventor iProperties. There are multiple types of properties. These properties will be either:
- Properties that live inside the file
- Properties that are stored in the Vault database.
DocumentService.UpdateFileProperties() is only able to update the Vault DB property value, it doesn’t update the property in a file. If you use DocumentService.UpdateFileProperties() the following happens:
1.You check out the file. It has a property value of “oldValue”.
2. You call DocumentService.UpdateFileProperties(), which changes the Vault property to “newValue”.
3. You check in the file. The file still has a value of “oldValue”, so when the Vault Server extracts the file properties, “newValue” is switched back to “oldValue”.
To use IExplorerUtil you need to call GetExplorerUtil or LoadExplorerUtil. GetExplorerUtil is for when you are running inside Vault Explorer.
This blog post has more information about IExplorerUtil.
Here are a couple of things I found about IExplorerUtil.
1. An IllegalInputParam exception is a somewhat generic exception thrown by the IExplorerUtil.UpdateFileProperties() when it gets any kind of unsuccessful outcome when trying to update the properties that isn’t the result of some kind of programming error (i.e. null reference exception, empty collections, etc.).
2. IExplorerUtils.UpdateProperties() will write back to the file before checking it in, but it does so in a temporary location so that the file in the working directory isn’t modified. This means that after the update, the file in the working directory doesn’t match the latest version in Vault, making the vault status out-of-date.
VB.NET Example
The 2013 VaultBrowserSample has an example of using IExplorerUtil. The 2014 VaultBrowserSample was updated to use the VDF download and so it does not rely on IExplorerUtil to do downloads anymore (in fact, IExplorerUtil doesn’t offer a download API anymore in the Vault 2014 SDK).
Here is an update to the VaultList SDK example that uses IExplorerUtil.UpdateFileProperties() to update the property of an Inventor part file. Notice that you do not need to explicitly check out or check in the file. (It is done by UpdateFileProperties however)
Download VaultList_With_IExplorerUtil
Here is the pertinent code from this example:
PrivateSub Button4_Click(sender As System.Object,
e As System.EventArgs) _
Handles Button4.Click
' For demonstration purposes,
' the information is hard-coded.
Dim results As VDF.Vault.Results.LogInResult =
VDF.Vault.Library.ConnectionManager.LogIn _
("localhost", "Vault", "Administrator", "",
VDF.Vault.Currency.Connections. _
AuthenticationFlags.Standard,
Nothing)
IfNot results.Success Then
Return
EndIf
Dim connection As _
VDF.Vault.Currency.Connections.Connection =
results.Connection
' Get IExplorerUtil using properties of the
' connection
Dim VaultExplorerUtil AsIExplorerUtil
VaultExplorerUtil =
ExplorerLoader.LoadExplorerUtil(
connection.Server,
connection.Vault,
connection.UserID,
connection.Ticket)
' Get the FileIteration of a file with
' this name
Dim oFileIteration As _
VDF.Vault.Currency.Entities.FileIteration =
getFileIteration _
("Box_with_holes_wb.ipt", connection)
' This is the new part number
Dim updateValueObj AsObject =
"wB - part number 2222"
' Get the Part number property
Dim myPropDefArray AsPropDef() =
connection.WebServiceManager.PropertyService.
FindPropertyDefinitionsBySystemNames _
("FILE", NewString() {"PartNumber"})
' This is the PropDef in the array
Dim myPropDef AsPropDef = myPropDefArray(0)
Try
' make a dictionary with the Part name
' PropDef and the new value for the
' part number
Dim propsDict AsDictionary(Of ACW.PropDef,
Object) =
NewDictionary(Of ACW.PropDef, Object)
propsDict.Add(myPropDef, updateValueObj)
'Update the part number
VaultExplorerUtil.UpdateFileProperties _
(oFileIteration, propsDict)
VaultExplorerUtil = Nothing
Catch ex AsException
MsgBox(ex.ToString())
VaultExplorerUtil = Nothing
EndTry
VDF.Vault.Library.ConnectionManager.
LogOut(connection)
EndSub