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