Undo Checkout of All Suppressed Occurrences

Undo Checkout of All Suppressed Occurrences

shiftctrl.io
Enthusiast Enthusiast
810 Views
2 Replies
Message 1 of 3

Undo Checkout of All Suppressed Occurrences

shiftctrl.io
Enthusiast
Enthusiast

Hi All,

 

I'm looking for some help/ideas on the best approach to check-in suppressed occurrences before deleting them. 

 

Below is a method in my application which will delete all suppressed occurrences, however I need to add some logic to first undo checkout of the suppressed component prior to the delete operation.

 

Any suggestions?

 

		public static void DeleteSuppressedOccurrences(Document document)
		{
			if ((int)document.DocumentType != Enum.AssemblyDocument) return;
			var assyDoc = (AssemblyDocument)document;
			var assyOccs = assyDoc.ComponentDefinition.Occurrences;
			foreach (ComponentOccurrence occ in assyOccs)
			{
				if (occ.Suppressed)
				{
					occ.Delete();
				}
			}
		}

 

0 Likes
Accepted solutions (1)
811 Views
2 Replies
Replies (2)
Message 2 of 3

yan.gauthier
Advocate
Advocate
Accepted solution

Hi, In order to do this, you need to use the Vault API. you should be able to install the Vault SDK from this folder if you have Vault installed:

 

C:\Program Files\Autodesk\Vault Basic 2020\SDK

 

I recommend you add a reference to the EdmSecurity dll from you inventor Bin file (C:\Program Files\Autodesk\Inventor 2020\Bin\Connectivity.InventorAddin.EdmAddin.dll)

 

then you should be able to write something like this :

using Autodesk.Connectivity.WebServices;
using Autodesk.Connectivity.WebServicesTools;
using Autodesk.DataManagement.Client.Framework.Vault.Currency.Properties;
using Connectivity.InventorAddin.EdmAddin;
using GenikAddin.DataControl;
using System;
using System.IO;
using VDF = Autodesk.DataManagement.Client.Framework;

//Code structure is not functional, just wanted to show which library i am using

//Use Inventor Vault Addin connection
EdmSecurity edmSecurity = EdmSecurity.Instance;

if (!edmSecurity.IsSignedIn())
            {
                edmSecurity.OnLoginButtonExecute(true); //simulate login button being pressed
            }

if (edmSecurity.VaultConnection is VDF.Vault.Currency.Connections.Connection connection)
            {
                // DocumentPath would be your file you want to undo check out
                string vaultpath = DocumentPath;

                string root = System.IO.Path.GetDirectoryName(edmSecurity.InventorApp.DesignProjectManager.ActiveDesignProject.FullFileName);

                 //replace PC Workspace path to become Vault Root
                 vaultpath = vaultpath.Replace(root, "$");

                 //vault uses forward slash (/) as separator instead of Windows backslash (\)
                vaultpath = vaultpath.Replace(System.IO.Path.DirectorySeparatorChar, '/');

                 //Find latest version of the file in the vault
                Autodesk.Connectivity.WebServices.File[] file = connection.WebServiceManager.DocumentService.FindLatestFilesByPaths(filepath);
                
                if (file[0].Id == -1)
                {
                    //File Was not found
                    return false;
                }

                //Create a fileIteration

                VDF.Vault.Currency.Entities.FileIteration fileIteration = new VDF.Vault.Currency.Entities.FileIteration(connection, file[0]);
}

 

From there I would try 

 

connection.WebServiceManager.DocumentService.UndoCheckoutFile(fileIteration.EntityMasterId);

 

 

Message 3 of 3

shiftctrl.io
Enthusiast
Enthusiast

This looks like good information, I'll be sure to try it out. Thanks for the code with comments.

0 Likes