iLogic to read Life Cycle State of Parts

iLogic to read Life Cycle State of Parts

CAD-One
Collaborator Collaborator
3,466 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,467 Views
27 Replies
Replies (27)
Message 2 of 28

AlexFielder
Advisor
Advisor

This is an interesting challenge for sure. I don't have anything specific (rule-wise) that'll do this just yet but wanted to ask:

In what context does having this information available help your particular workflow?

0 Likes
Message 3 of 28

JhoelForshav
Mentor
Mentor

I did some testing and this works for me. It takes a partnumber and gives back the Life Cycle State of that item in vault.

Just Write some functionallity to traverse your assy and obtain all partnumbers and then run them through this function 🙂

 

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

Sub Main
	MsgBox(GetState("100001")) 'Put in the PartNumber (itemnumber)
	
End Sub


Public Function GetState(PartNumber As String) 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 = Connection.WebServiceManager.ItemService.GetLatestItemByItemNumber(PartNumber)
	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
End If
Return oState
End Function
 
Message 4 of 28

AlexFielder
Advisor
Advisor

TIL you can do this:

 

AddReference "Connectivity.InventorAddin.EdmAddin"
Imports edm = Connectivity.InventorAddin.EdmAddin
Dim Connection As VDF.Vault.Currency.Connections.Connection = edm.EdmSecurity.Instance.VaultConnection()

🙂

Message 5 of 28

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

@CAD-One,

 

Try below iLogic code to get life cycle state of current document ("C:\$WorkingFolder\" is user specific and need to update before running this code).

 

AddReference "Autodesk.Connectivity.WebServices.dll"
Imports AWS = Autodesk.Connectivity.WebServices
AddReference "Autodesk.DataManagement.Client.Framework.Vault.dll"
Imports VDF = Autodesk.DataManagement.Client.Framework 
AddReference "Connectivity.Application.VaultBase.dll"
Imports VB = Connectivity.Application.VaultBase

Dim mVltCon As VDF.Vault.Currency.Connections.Connection 
mVltCon = VB.ConnectionManager.Instance.Connection
 
If  mVltCon Is Nothing Then
	Messagebox.Show("Not Logged In to Vault! - Login first and repeat executing this rule.")
	Exit Sub
End If

Dim VaultPath As String = ThisDoc.PathAndFileName(True)
VaultPath = VaultPath.Replace("C:\$WorkingFolder\", "$/")
'flip the slashes
VaultPath = VaultPath.Replace("\", "/")

Dim VaultPaths() As String = New String() {VaultPath}
 
Dim wsFiels() As AWS.File = mVltCon.WebServiceManager.DocumentService.FindLatestFilesByPaths(VaultPaths)
 
Dim mFileIt As VDF.Vault.Currency.Entities.FileIteration = New VDF.Vault.Currency.Entities.FileIteration(conn,wsFiels(0))
Dim lifeCycleInfo As VDF.Vault.Currency.Entities.FileLifecycleInfo = mFileIt.LifecycleInfo 

Messagebox.Show(lifeCycleInfo.Statename)

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 6 of 28

machiel.veldkamp
Collaborator
Collaborator

Is it also possible to read the CheckedIn status?

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

___________________________
0 Likes
Message 7 of 28

chandra.shekar.g
Autodesk Support
Autodesk Support

@machiel.veldkamp,

 

Try below iLogic code to get status of vault file whether file is checked out or not.

 

AddReference "Autodesk.Connectivity.WebServices.dll"
Imports AWS = Autodesk.Connectivity.WebServices
AddReference "Autodesk.DataManagement.Client.Framework.Vault.dll"
Imports VDF = Autodesk.DataManagement.Client.Framework 
AddReference "Connectivity.Application.VaultBase.dll"
Imports VB = Connectivity.Application.VaultBase

Dim mVltCon As VDF.Vault.Currency.Connections.Connection 
mVltCon = VB.ConnectionManager.Instance.Connection
 
If  mVltCon Is Nothing Then
	Messagebox.Show("Not Logged In to Vault! - Login first and repeat executing this rule.")
	Exit Sub
End If

Dim VaultPath As String = ThisDoc.PathAndFileName(True)
VaultPath = VaultPath.Replace("C:\$WorkingFolder\", "$/")
'flip the slashes
VaultPath = VaultPath.Replace("\", "/")

Dim VaultPaths() As String = New String() {VaultPath}
 
Dim wsFiels() As AWS.File = mVltCon.WebServiceManager.DocumentService.FindLatestFilesByPaths(VaultPaths)
 
Dim mFileIt As VDF.Vault.Currency.Entities.FileIteration = New VDF.Vault.Currency.Entities.FileIteration(conn,wsFiels(0))
Messagebox.Show(mFileIt.IsCheckedOut)

 

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 8 of 28

CAD-One
Collaborator
Collaborator

I have obsoleted a part in vault. Users have been using it for several years in their products’ design. 

 

I am looking for a routine to check every time the assembly opened. Looks like it’s not as easy. 

C1
Inventor Professional 2020
Vault Professional 2020
AutoCAD 2020
0 Likes
Message 9 of 28

CAD-One
Collaborator
Collaborator

Must say this is cool. Unfortunately, since we don’t use ‘Items’ not useful for me. 

 

C1
Inventor Professional 2020
Vault Professional 2020
AutoCAD 2020
0 Likes
Message 10 of 28

CAD-One
Collaborator
Collaborator

Thanks a lot. This is really close. I will have to expand it into looping to parts and subassemblies. 

C1
Inventor Professional 2020
Vault Professional 2020
AutoCAD 2020
0 Likes
Message 11 of 28

chandra.shekar.g
Autodesk Support
Autodesk Support

@CAD-One,

 

If any post is relevant to answer your question, click on "Accept as solution".

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 12 of 28

My messing box have no text in it ... any idear why ? when I use it out of the box

0 Likes
Message 13 of 28

chandra.shekar.g
Autodesk Support
Autodesk Support

@Darkforce_the_ilogic_guy,

 

Guessing that vault is not updated properly. In below path, "C:\$WorkingFolder\" is my vault path and it is different for your vault connection.

VaultPath = VaultPath.Replace("C:\$WorkingFolder\", "$/")

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 14 of 28

Can you help my found out what I need to change it to ? how can I finde my  VaultPath ?

0 Likes
Message 15 of 28

chandra.shekar.g
Autodesk Support
Autodesk Support

@Darkforce_the_ilogic_guy,

 

Vault path is location of "Vault.ipj" file. It can be searched in windows explorer (This PC or My Computer).

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 16 of 28

Vault.ipj ? is that a files that are location on my computer or the vault server ?  and does this even work if you Vaur lt Server is not local on your computer ?

 

 

0 Likes
Message 17 of 28

chandra.shekar.g
Autodesk Support
Autodesk Support

@Darkforce_the_ilogic_guy,

 

Yes, "Vault.ipj" file is located at "My computer" or "This PC". When Vault file is downloaded or checked out, file is always located at this folder (Vault.ipj).

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 18 of 28

Are we talking about the projekt file ? If so can you give my a copy of the code that will work ?

Folder name is this one 

C:\Working Folder

 

And project file is call Kallesoe-2018.ipj in my system 

 

We are using vault pro

0 Likes
Message 19 of 28

chandra.shekar.g
Autodesk Support
Autodesk Support

@Darkforce_the_ilogic_guy,

 

Then, vault path may be modified as below.

VaultPath = VaultPath.Replace("C:\$Working Folder\", "$/")

or

 

VaultPath = "C:\Working Folder\" 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 20 of 28

does this work with item workflow ?

0 Likes