Community
Vault Customization
Share your knowledge, ask questions, and explore popular Vault API, Data Standard, and VBA topics related to programming, creating add-ins, or working with the Vault API.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Change life cycle state to 'Released' with Inventor API.

1 REPLY 1
SOLVED
Reply
Message 1 of 2
harvey_craig2RCUH
162 Views, 1 Reply

Change life cycle state to 'Released' with Inventor API.

I would like to have dialog box asking the user if they would like to release their drawing, if it's not already so, upon exit. I can read the current lifecycle state of the Vaulted drawing but I can't change it as it's a read-only property. How would I do this? 
 
 
Imports Autodesk.DataManagement.Client.Framework.Vault
Imports Autodesk.Connectivity.WebServices
Imports VDF = Autodesk.DataManagement.Client.Framework
Imports ACW = Autodesk.Connectivity.WebServices
Imports AWS = Autodesk.Connectivity.WebServices
Imports VB = Connectivity.Application.VaultBase
Imports Autodesk.DataManagement.Client.Framework.Vault.Currency
AddReference "Autodesk.DataManagement.Client.Framework.Vault.dll"
AddReference "Autodesk.DataManagement.Client.Framework.dll"
AddReference "Connectivity.Application.VaultBase.dll"
AddReference "Autodesk.Connectivity.WebServices.dll"


Dim oFilePath As String = ThisDoc.Document.FullDocumentName

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

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

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

If mFileIt.LifecycleInfo.StateId = 22 Then '22 = released
	Logger.Info("Drawing already released. Exiting rule.")
	Return
End If
If mFileIt.IsCheckedOut = True Then
	Logger.Info("Drawing checked out. Drawing must be checked in to release. Exiting rule.")
	Return
End If
MessageBox.Show("You are exiting a checked in, WIP drawing. Would you like to release?", "Release?", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If result = DialogResult.Yes Then
    ' Change the lifecycle state to "Released"
Else
	Return
End If


 

1 REPLY 1
Message 2 of 2

@harvey_craig2RCUH 

 

Hi,

In my opinion, you should use the method located in WebServiceManager.DocumentServiceExtensions.UpdateFileLifeCycleStates

 

m_baczewski_0-1732106783588.png

 

I am sharing with you my method, which I wrote to change the lifecycle of a given item in the vault. I also use other methods in it, but I’m sure you’ll understand what it’s about.

 

public static void UpdateFileState(Connection mVault, string fileName)
        {
            try
            {
                LfCycDef[] states = mVault.WebServiceManager.LifeCycleService.GetAllLifeCycleDefinitions();

                Dictionary<string, long> dicState = new Dictionary<string, long>();

                foreach (LfCycDef state in states)
                {
                    if (state.DispName == "Standardowy cykl zwolnienia plików projektowych")
                    {
                        foreach (LfCycState lfState in state.StateArray)
                        {
                            dicState.Add(lfState.DispName, lfState.Id);
                        }
                        break;
                    }
                }
                File[] files = FilesInFolder.GetFilesIdFromFolder(mVault, fileName);

                List<long> filesToChangeState = new List<long>();
                List<long> stateIds = new List<long>();

                foreach (File file in files)
                {

                    filesToChangeState.Add(long.Parse(file.MasterId.ToString()));
                    try
                    {
                        stateIds.Add(dicState["Do przeglądu"]);
                    }
                    catch
                    {
                        throw new Exception("Nieznany typ stanu");
                    }
                }
                mVault.WebServiceManager.DocumentServiceExtensions.UpdateFileLifeCycleStates(filesToChangeState.ToArray(), stateIds.ToArray(), "W trakcie przeglądu");
                
            }
            catch(Exception ex)
            {
                throw ex;
            }
  
        }

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report