Hi @Darkforce_the_ilogic_guy
Try this rule. It works for me 🙂
AddReference "Autodesk.Connectivity.WebServices"
AddReference "Autodesk.DataManagement.Client.Framework"
AddReference "Autodesk.DataManagement.Client.Framework.Vault"
AddReference "Connectivity.InventorAddin.EdmAddin"
Imports VDF = Autodesk.DataManagement.Client.Framework
Imports Autodesk.DataManagement.Client.Framework.Vault.Currency.Connections
Imports edm = Connectivity.InventorAddin.EdmAddin
Imports ACW = Autodesk.Connectivity.WebServices
Imports Autodesk.DataManagement.Client.Framework.Vault.Currency.Properties
Sub Main
Dim Connection As VDF.Vault.Currency.Connections.Connection = edm.EdmSecurity.Instance.VaultConnection()
If Connection Is Nothing Then
MsgBox("No vault connection...")
Exit Sub
End If
'Check if file is checked out by me or file doesn't exist in vault
If FileCheckedOutByMe(Connection, ThisDoc.Document.FullFileName)
Dim revNum As String
Try
revNum = GetRevNum(Connection, iProperties.Value("Project", "Part Number"))
Catch
revNum = 0
End Try
iProperties.Value("Project", "Revision Number") = revNum
End If
End Sub
Function GetRevNum(conn As VDF.Vault.Currency.Connections.Connection, PartNumber As String) As String
Dim item As Autodesk.Connectivity.WebServices.Item = conn.WebServiceManager.ItemService.GetLatestItemByItemNumber(PartNumber)
Return item.RevNum
End Function
Function FileCheckedOutByMe(conn As VDF.Vault.Currency.Connections.Connection, fileName As String)
Try
Dim oFileInfo As New System.IO.FileInfo(fileName)
Catch
Return True
End Try
Dim oVaultFileName As String
Dim oWF As String = conn.WorkingFoldersManager.GetWorkingFolder("$/").FullPath
If fileName.ToLower().Contains(oWF.ToLower()) Then
oVaultFileName = fileName.Replace(oWF, "$/").Replace("\", "/")
Else
'File Not in vault
Return True
End If
Dim oWSmgr As Autodesk.Connectivity.WebServicesTools.WebServiceManager = conn.WebServiceManager
Dim oFile As ACW.File = oWSmgr.DocumentService.FindLatestFilesByPaths(New String() {oVaultFileName }).FirstOrDefault()
If oFile.Id = -1 Then
'File Not in vault
Return True
End If
Dim oFileIteration As New VDF.Vault.Currency.Entities.FileIteration(conn, oFile)
Dim oProps As PropertyDefinitionDictionary = conn.PropertyManager.GetPropertyDefinitions(VDF.Vault.Currency.Entities.EntityClassIds.Files, Nothing, PropertyDefinitionFilter.IncludeAll)
Dim oVaultStatus As PropertyDefinition = oProps(PropertyDefinitionIds.Client.VaultStatus)
Dim status As EntityStatusImageInfo = TryCast(conn.PropertyManager.GetPropertyValue(oFileIteration, oVaultStatus, Nothing), EntityStatusImageInfo)
Dim oCheckoutState As EntityStatus.CheckoutStateEnum = status.Status.CheckoutState
If oCheckoutState = EntityStatus.CheckoutStateEnum.CheckedOutByCurrentUser
Return True
Else
Return False
End If
End Function