not run ilogic code if file is not check out.. How ?

not run ilogic code if file is not check out.. How ?

Darkforce_the_ilogic_guy
Advisor Advisor
767 Views
4 Replies
Message 1 of 5

not run ilogic code if file is not check out.. How ?

Darkforce_the_ilogic_guy
Advisor
Advisor

I have this code ... that can get rev number form item in vault, but is there a way to get the file status?  that I can use to  exit an ilogic code if I do not have the file check out to me..

 

Sub Main


'is this file check out to me if yes run reste of the code, if not exit sub




	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
0 Likes
Accepted solutions (1)
768 Views
4 Replies
Replies (4)
Message 2 of 5

pball
Mentor
Mentor

Here is some iLogic code I found/modified to get the Vault status of an item.

 

Public Sub Main
	MsgBox(VaultReadOnly)
End Sub

Public Function VaultReadOnly() As Boolean
	If (ThisApplication.ApplicationAddIns.ItemById("{48B682BC-42E6-4953-84C5-3D253B52E77B}").Activated = False) Then Return False
	status = VaultStatus()
	If (status = 0 Or status = 1) Then 
		Return False
	Else 
		Return True
	End If
End Function

Public Function VaultStatus() As Integer
	If (ThisApplication.ApplicationAddIns.ItemById("{48B682BC-42E6-4953-84C5-3D253B52E77B}").Activated = False) Then Return 0
	If (TCCI("VaultDataCardtop") = False) Then
		Return 0 'Not in Vault
	ElseIf (TCCI("VaultDataCardtop") = True And TCCI("VaultUndoCheckouttop") = True) Then
		Return 1 'In Vault, Checked out
	ElseIf (TCCI("VaultDataCardtop") = True And TCCI("VaultCheckouttop") = True) Then
		Return 2 'In Vault, Not checked out
	ElseIf (TCCI("VaultDataCardtop") = True And TCCI("VaultCheckouttop") = False And TCCI("VaultCheckintop") = False) Then
		Return 3 'In Vault, Locked
	End If
End Function

Public Function TCCI(VaultParam As String)
	Return ThisApplication.CommandManager.ControlDefinitions.Item(VaultParam).Enabled
End Function

 

Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
Message 3 of 5

JhoelForshav
Mentor
Mentor
Accepted solution

@Darkforce_the_ilogic_guy @pball 

That code seems to work 🙂 I suspect however that it returns the vaultstatus of the active document, so if the function is being called for all components of an assembly, or on save event where the active document is an assembly that in turn saves component documents etc it will not work as expected.

I modified you original rule to check vault status.

This rule takes the filename and translates it to a vault path. Then checks the vault status via vault API. I think it's a more robust way to do it. @pball s code is very clever and quick however and if the rule is always supposed to check the active edit document only it shouldn't be an issue at all 🙂

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

 

Message 4 of 5

Darkforce_the_ilogic_guy
Advisor
Advisor

yes it seens to work.. Ofcause I have to get this code inside all of my code  🙂

 

 

Thanks for the help

Message 5 of 5

JhoelForshav
Mentor
Mentor

@Darkforce_the_ilogic_guy wrote:

yes it seens to work.. Ofcause I have to get this code inside all of my code  🙂

 


If I were you I'd just add it as an external rule in my external rule standard directory and have it trigger Before Save Document for All Documents 🙂

Skärmbild 2023-05-11 234633.png