Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

can I use ilogic to read Rev Number on the Item for a part ?

Darkforce_the_ilogic_guy
Advisor

can I use ilogic to read Rev Number on the Item for a part ?

Darkforce_the_ilogic_guy
Advisor
Advisor

can I use ilogic to read Rev Number on the Item for a part ?

 

I want to make sure that Revision on a file is always the same as the Rev number on the item for that file. Is there a way to read the Rev number on the item and compair it to the Revision of the files.. and if they are not the same 

 

then change the revision on the file to the Rev number on the item.. If there is no item jet.. Rev number need to be 0

 

I want to do this on save using ilogic

 

 

 

 

 

0 Likes
Reply
Accepted solutions (1)
418 Views
3 Replies
Replies (3)

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @Darkforce_the_ilogic_guy 
Try this iLogic rule 🙂

 

AddReference "Autodesk.Connectivity.WebServices"
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

Sub Main
	Dim revNum As String
	Try
	revNum = GetRevNum(iProperties.Value("Project", "Part Number"))
	Catch
	revNum = 0	
	End Try
	
	iProperties.Value("Project", "Revision Number") = revNum
End Sub

Public Function GetRevNum(PartNumber As String) As String
Dim Connection As VDF.Vault.Currency.Connections.Connection = edm.EdmSecurity.Instance.VaultConnection()
If Not Connection Is Nothing Then
	Dim item As Autodesk.Connectivity.WebServices.Item = Connection.WebServiceManager.ItemService.GetLatestItemByItemNumber(PartNumber)
	Return item.RevNum
End If

End Function

 

It worked for me with Inventor professional 2022 and Vault Professional 2022 🙂

Darkforce_the_ilogic_guy
Advisor
Advisor

yes it seens to work. Do you alså know how I can check if the have the file check out, and only run the code if the user have the file check out ?

 

 

 

0 Likes

JhoelForshav
Mentor
Mentor

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
0 Likes