iLogic to read Life Cycle State of Parts

iLogic to read Life Cycle State of Parts

CAD-One
Collaborator Collaborator
3,501 Views
27 Replies
Message 1 of 28

iLogic to read Life Cycle State of Parts

CAD-One
Collaborator
Collaborator

While writing a iLogic code in an assembly file, is there a code/snippet to check the "Life Cycle State" of a parts/sub assemblies"

 

Basically, I want to message box to pop up with a list of parts/sub assemblies those are "Obsolete" in vault.

C1
Inventor Professional 2020
Vault Professional 2020
AutoCAD 2020
0 Likes
Accepted solutions (1)
3,502 Views
27 Replies
Replies (27)
Message 21 of 28

chandra.shekar.g
Autodesk Support
Autodesk Support

@Darkforce_the_ilogic_guy,

 

Hoping that it should also work for item workflow.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 22 of 28

well I can't get it to on my computer...I have even try to make to it to one file. finde det vault path in vault("Path") , but no matter what i do ... it come back no matter what life cycke stat the part are in

0 Likes
Message 23 of 28

goran.nilssonRSJCU
Participant
Participant

Cad-one Have you found a solution which loop all parts and subassemblies? I'm looking for same solution.

0 Likes
Message 24 of 28

Anonymous
Not applicable

Hello Jhoel Forshav

 

Thank you very much for this code, I've been looking for this for so long.

Have you tried making a function that can change state of an item directly from inventor? you know update the item and change from WIP to something else and the other way around.

0 Likes
Message 25 of 28

JhoelForshav
Mentor
Mentor

Hi @Anonymous 

Try this iLogic rule to change item state:

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
Friend Module ExtensionMethods
	Sub New()
	End Sub
	<System.Runtime.CompilerServices.Extension> _
	Friend Function ToSingleArray(Of T)(obj As T) As T()
		Return New T() {obj }
	End Function
End Module
Class ThisRule

	Sub Main

		ChangeState("0501140") 'Put in the PartNumber (itemnumber)

	End Sub

	Public Sub ChangeState(PartNumber As String)
		Dim Connection As VDF.Vault.Currency.Connections.Connection = edm.EdmSecurity.Instance.VaultConnection()
		Dim oState As String = String.Empty
		If Not Connection Is Nothing Then
			Dim item As Autodesk.Connectivity.WebServices.Item
			Try
				item = Connection.WebServiceManager.ItemService.GetLatestItemByItemNumber(PartNumber)
			Catch
				MessageBox.Show("Couldn't find item " & PartNumber, "No item found", MessageBoxButtons.OK, MessageBoxIcon.Error)
				Return
			End Try
			Dim lifeCycleDef As Autodesk.Connectivity.WebServices.LfCycDef = Connection.WebServiceManager.LifeCycleService.GetLifeCycleDefinitionsByIds(item.LfCyc.LfCycDefId.ToSingleArray()).First()
			Dim stateMap As Dictionary(Of Long, Autodesk.Connectivity.WebServices.LfCycState) = lifeCycleDef.StateArray.ToDictionary(Function(n) n.Id)
			oState = stateMap(item.LfCycStateId).DispName

			Dim oArrList As New ArrayList()

			For Each trans As Autodesk.Connectivity.WebServices.LfCycTrans In lifeCycleDef.TransArray
				' figure out the transitions from the current state and add them to the combo box
				If trans.FromId = item.LfCycStateId Then
					Dim oitem As New TransItem(trans, stateMap(trans.ToId))
					oArrList.Add(oitem)
				End If
			Next
			Dim transItem As TransItem = TryCast(InputListBox("Current state: " & oState, oArrList, Nothing, "Change state for item: " & PartNumber), TransItem)
			If transItem Is Nothing Then
				MessageBox.Show("No new state selected.")
				Return
			End If
			Try
				Dim updatedItem As Autodesk.Connectivity.WebServices.Item = Connection.WebServiceManager.ItemService.UpdateItemLifeCycleStates(item.MasterId.ToSingleArray(), transItem.ToState.Id.ToSingleArray(), "state change example").First()
				MessageBox.Show("Item state successfully changed from " & oState & " to " & transItem.ToString & "!", "Item state changed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
			Catch
				Dim oRetry As DialogResult = MessageBox.Show("Couldn't change item " & PartNumber & " from " & oState & vbCrLf & _
				"to " & transItem.ToString, "Change failed", MessageBoxButtons.RetryCancel, MessageBoxIcon.Information)
				If oRetry = DialogResult.Retry
					ChangeState(PartNumber)
				Else
					Return
				End If
			End Try

		End If
	End Sub
End Class
Public Class TransItem
	Public Property Transition() As Autodesk.Connectivity.WebServices.LfCycTrans
		Get
			Return m_Transition
		End Get
		Private Set
			m_Transition = value
		End Set
	End Property
	Private m_Transition As Autodesk.Connectivity.WebServices.LfCycTrans
	Public Property ToState() As Autodesk.Connectivity.WebServices.LfCycState
		Get
			Return m_ToState
		End Get
		Private Set
			m_ToState = value
		End Set
	End Property
	Private m_ToState As Autodesk.Connectivity.WebServices.LfCycState

	Public Sub New(trans As Autodesk.Connectivity.WebServices.LfCycTrans, toState As Autodesk.Connectivity.WebServices.LfCycState)
		Me.Transition = trans
		Me.ToState = toState
	End Sub

	Public Overrides Function ToString() As String
		Return ToState.DispName
	End Function

End Class
Message 26 of 28

Anonymous
Not applicable

Thank you very much for your reply

 

That is what I was looking for, is there a chance that it can update/assign item before changing state?

0 Likes
Message 27 of 28

JhoelForshav
Mentor
Mentor

@Anonymous 

I'm sure it's doable. I assume it would take me some time to accomlish though since I'm no Vault API expert, and I'm going on summer vacation in a couple of hours so I won't be able to help out for some time.

 

Good luck on your project! I'd recommend asking in the Vault Customization forum insted since everything we do in this rule is through the Vault API 🙂

Message 28 of 28

Anonymous
Not applicable

Thank you so much for your help, you have helped me to get further.

 

I am working on the update/assign item right now.