Acquire Vault Files with Inventor API

Acquire Vault Files with Inventor API

machiel.veldkamp
Collaborator Collaborator
5,158 Views
25 Replies
Message 1 of 26

Acquire Vault Files with Inventor API

machiel.veldkamp
Collaborator
Collaborator

Hi!

 

I'm looking for a way to 'Get' files from the Vault with iLogic

 

What I have so far:

All my wanted files are in a VBA Dictionary stored as Filename.extension

 

 

Imports System.Text
Imports System.IO
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.Properties

AddReference "Autodesk.DataManagement.Client.Framework.Vault.dll"
AddReference "Connectivity.Application.VaultBase.dll"
AddReference "Autodesk.Connectivity.WebServices.dll"

 

 

For i = 0 To oTotalDict.Count - 1 'oTotalDict(String(C:/path/.../filename.extension), Int(QTY)) 
		'oCount = oTotalDict.Values(i)

		Key = oTotalDict.Keys(i)
		dwgPath = Left(key, Len(Key) - 3) & "dwg"

		VaultPartPath = Key.Replace("C:\Company\Vault\", "$/")
		VaultPartPath = VaultPartPath.Replace("\", "/")

		VaultDWGPath = dwgPath.Replace("C:\Company\Vault\", "$/")
		VaultDWGPath = VaultDWGPath.Replace("\", "/")

		Dim VaultDWGPaths() As String = New String() {VaultDWGPath }
		Dim VaultPartPaths() As String = New String() {VaultPartPath }


		Dim wsFiels() As AWS.File = mVltCon.WebServiceManager.DocumentService.FindLatestFilesByPaths(VaultDWGPaths)
		Dim wsFiels2() As AWS.File = mVltCon.WebServiceManager.DocumentService.FindLatestFilesByPaths(VaultPartPaths)

		'Ts file exists in the Vault. 
		Dim DwgFileIt As VDF.Vault.Currency.Entities.FileIteration = New VDF.Vault.Currency.Entities.FileIteration(conn, wsFiels(0)) 		'DWG HERE
		Dim PartFileIt As VDF.Vault.Currency.Entities.FileIteration = New VDF.Vault.Currency.Entities.FileIteration(conn, wsFiels2(0)) 	'PART HERE (IPT/IAM)

		Dim lifeCycleInfo As VDF.Vault.Currency.Entities.FileLifecycleInfo = DwgFileIt.LifecycleInfo


		Dim DWGIsCheckedOut As Boolean = DwgFileIt.IsCheckedOut
		Dim PartIsCheckedOut As Boolean = PartFileIt.IsCheckedOut

		If DWGIsCheckedOut = True
			Trace.WriteLine("CHECKED OUT: " & dwgPath)
		Else If PartIsCheckedOut = True
		Trace.WriteLine("CHECKED OUT: " & Key)
		End If

		If Not lifeCycleInfo.StateId = - 1 'IN VAULT
			'Trace.WriteLine("File not in C?: " & dwgPath)
			If System.IO.File.Exists(dwgPath)
				'Trace.WriteLine("YES IN VAULT, YES ON C: " & dwgPath & " Status: " & lifeCycleInfo.StateName)' & " ID:" & lifeCycleInfo.StateId)
			End If
			If Not System.IO.File.Exists(dwgPath)
				Trace.WriteLine("YES IN VAULT, NOT ON C: " & dwgPath & " Status: " & lifeCycleInfo.StateName)' & " ID:" & lifeCycleInfo.StateId)
			End If

		End If
		If lifeCycleInfo.StateId = - 1 'FILE NOT IN VAULT. 
			'Trace.WriteLine("File not in Vault?: " & dwgPath)
			If System.IO.File.Exists(dwgPath)
				Trace.WriteLine("ON C, NOT IN VAULT: " & dwgPath & " Status: " & lifeCycleInfo.StateName)' & " ID:" & lifeCycleInfo.StateId)

			End If
			If Not System.IO.File.Exists(dwgPath)
				'Trace.WriteLine("NOT ON C, NOT IN VAULT: " & dwgPath & " Status: " & lifeCycleInfo.StateName)' & " ID:" & lifeCycleInfo.StateId)
			End If
		End If
		'MessageBox.Show(lifeCycleInfo.StateName)
	Next

 

I want to get the files that are not on C but are located in the Vault. 

 

I found some topics that might be interesting but I don't know how to get the files themselves yet. 

 

https://forums.autodesk.com/t5/inventor-customization/i-made-a-ilogic-version-checker-for-my-colleag...

 

https://forums.autodesk.com/t5/inventor-customization/ilogic-open-file-from-vault/td-p/5701827

 

https://adndevblog.typepad.com/manufacturing/2019/04/connecting-vault-and-accessing-vault-file-statu...

 

Anyone that knows how to get a file from vault just from the fullpathname?

 

The Vault API Help gives this example but I don't know how to use it. 

 

Imports VDF = Autodesk.DataManagement.Client.Framework
 
Public Sub DownlodFiles(fileIters As ICollection(OfVDF.Vault.Currency.Entities.FileIteration))
       ' download individual files to a temp location
       Dim settings As NewVDF.Vault.Settings.AcquireFilesSettings(m_conn)
       settings.LocalPath = NewVDF.Currency.FolderPathAbsolute("c:\temp")
       For Each fileIter AsVDF.Vault.Currency.Entities.FileIteration In fileIters
              settings.AddFileToAcquire(fileIter, _ _
              VDF.Vault.Settings.AcquireFilesSettings.AcquisitionOption.Download)
       Next
 
       Dim results As VDF.Vault.Results.AcquireFilesResults = _
           m_conn.FileManager.AcquireFiles(settings)
End Sub
 
Public Sub DownloadAssembly(topLevelAssembly AsVDF.Vault.Currency.Entities.FileIteration)
       ' download the latest version of the assembly to working folders
       Dim settings As NewVDF.Vault.Settings.AcquireFilesSettings(m_conn)
    settings.OptionsRelationshipGathering.FileRelationshipSettings.IncludeChildren = True
    settings.OptionsRelationshipGathering.FileRelationshipSettings.RecurseChildren = True
    settings.OptionsRelationshipGathering.FileRelationshipSettings.VersionGatheringOption = _
           VDF.Vault.Currency.VersionGatheringOption.Latest
       settings.AddFileToAcquire(topLevelAssembly, _
          VDF.Vault.Settings.AcquireFilesSettings.AcquisitionOption.Download)
 
       Dim results As VDF.Vault.Results.AcquireFilesResults = _
           m_conn.FileManager.AcquireFiles(settings)
End Sub
 
Public Sub DownloadDialog(fileIter AsVDF.Vault.Currency.Entities.FileIteration, _
    parentWindowHandle As IntPtr)
       ' pop up the Get/Checkout dialog
       Dim settings As NewVDF.Vault.Forms.Settings.InteractiveAcquireFileSettings( _
           m_conn, parentWindowHandle, "Download files")
       settings.AddEntityToAcquire(fileIter)
 
       VDF.Vault.Forms.Library.AcquireFiles(settings)
End Sub

 

 

 

 

 

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

___________________________
0 Likes
5,159 Views
25 Replies
Replies (25)
Message 21 of 26

bradeneuropeArthur
Mentor
Mentor

Hi,

 

For the idea you have there is already a nice tool available within vault for it, called "synch. workspace" found in the ribbon of vault!!!

Also in the home screen of inventor you have these possibilities (see what is missing in vault)!!!

 

What I understand is that you would like to check if there are files in your workspace that haven't been checked in.

So what needs to be done is to check if files and folders are not in the vault at all and if files are in the vault but with a newer version in the workspace. 

Question is what needs to be done after this check?

  • check in files that are in vault but checked out to you with a newer version?
  • undo check out files that are in vault but checked out to you with a newer version?
  • check in files that are in vault but checked out to you with a same version?
  • undo check out files that are in vault but checked out to you with a same version?
  • add files to vault that are missing vault ?
  • add create folders that are missing in vault?
  • do nothing and only make the user aware of this

Additional remark:

The code provided is very complex and company specific, and hard to understand.

I would take a look at the possibilities to program within another language like VB.net, which makes it at some points easier to understand. 

 

Regards,

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 22 of 26

machiel.veldkamp
Collaborator
Collaborator

For the idea you have there is already a nice tool available within vault for it, called "synch. workspace" found in the ribbon of vault!!!

- That's true! Technically that might work as well. The sync workspace button takes several hours to complete it's thing though so we never use it and manually get folders from the vault

 

 

Also in the home screen of inventor you have these possibilities (see what is missing in vault)!!!

- We don't use the homescreen of inventor. 🙂 It's too slow.

 

What I understand is that you would like to check if there are files in your workspace that haven't been checked in.

So what needs to be done is to check if files and folders are not in the vault at all and if files are in the vault but with a newer version in the workspace. 

Question is what needs to be done after this check?

  • check in files that are in vault but checked out to you with a newer version?
    • In case of checked out files the rule needs to EXIT and the user needs to be notified and User  needs to check in files manually
  • undo check out files that are in vault but checked out to you with a newer version?
    •  
  • check in files that are in vault but checked out to you with a same version?
    •  
  • undo check out files that are in vault but checked out to you with a same version?
    • Yes. That seems like a safe option. 
  • add files to vault that are missing vault ?
    • No! Everything that goes into vault needs to be a manual thing. 
  • add create folders that are missing in vault?
    • No! Everything that goes into vault needs to be a manual thing. 
  • do nothing and only make the user aware of this
    • Yes. Exactly

Additional remark:

The code provided is very complex and company specific, and hard to understand.

I would take a look at the possibilities to program within another language like VB.net, which makes it at some points easier to understand. 

 

-----------------------------------

 

So. To simplify a bit. 

 

This rule basically will be run when the drawingpacket is already finnished and complete. 

The user runs the rule to export all drawings and print them all in bulk. 

 

Right now I only have a notice when files are missing or are checked out. 

 

I'd like to add:

- a new Sub DownloadFilesFromVault that only needs FullFilePath to work. (C:/Company/Vault/Folder/.../File.ipt)

- a way to detect out of sync files. IF 'C' is older than Vault -> DownloadFilesFromVault() 

 

I already have a way to warn users if files are checked out. Again, the user needs to check those files in manually. 

 

 

P.S.

I haven't found a way to install a VB.net program yet. It keeps asking me for a license but I don't have one. 

Also, I really appreciate you looking into this. Really.

I don't need a complete rewrite of my code I just need one new Sub and thought I'd supply some context 😉

 

____________________

 

Final thing. I tried some stuff yesterday and I think I'm slowly getting things done?

 

I'm now getting weird error messages which I didn't see before:

 

image.pngimage.png

 

What I now have is this (you supplied almost all of it I think):

 

Dim fname As String = dwgPath
				Dim file1 As Autodesk.Connectivity.WebServices.File()
				file1 = mVltCon.WebServiceManager.DocumentService.FindLatestFilesByPaths({fname})

				If file1.Length <> 0 Then
					Trace.WriteLine("Start test")
					Dim oFileIteration As VDF.Vault.Currency.Entities.FileIteration = Nothing
					Trace.WriteLine("FilleIteration 1")
					
					oFileIteration = New VDF.Vault.Currency.Entities.FileIteration(mVltCon, file1(0))
					'oFileIteration = GetFileIteration(fname, mVltCon)
					Trace.WriteLine("FilleIteration 1.5")
					
					Trace.WriteLine("FilleIteration 2")
					GetSelectedFiles(file1(0),mVltCon,"C:\TEMP")

				End If
Public Sub GetSelectedFiles(File As Autodesk.Connectivity.WebServices.File, m_connection As VDF.Vault.Currency.Connections.Connection, strTargetFolder As String)
        MsgBox(m_connection.IsConnected)

        Dim fileIter As VDF.Vault.Currency.Entities.FileIteration = m_connection.FileManager.GetFilesByIterationIds(New Long() {File.Id}).First().Value
		MessageBox.Show("Message", "Title")
        Dim targetDir As System.IO.DirectoryInfo = New System.IO.DirectoryInfo(strTargetFolder)
        If Not targetDir.Exists Then
            targetDir.Create()
        End If
		
        Dim downloadSettings As Autodesk.DataManagement.Client.Framework.Vault.Settings.AcquireFilesSettings = New VDF.Vault.Settings.AcquireFilesSettings(m_connection)
        downloadSettings.LocalPath = New Autodesk.DataManagement.Client.Framework.Currency.FolderPathAbsolute(targetDir.FullName)
        downloadSettings.CreateMetaDataFile = True
        downloadSettings.AddFileToAcquire(fileIter, Autodesk.DataManagement.Client.Framework.Vault.Settings.AcquireFilesSettings.AcquisitionOption.Download)
		

        m_connection.FileManager.AcquireFiles(downloadSettings)
		
End Sub

 

 

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

___________________________
0 Likes
Message 23 of 26

Anonymous
Not applicable

Hi @machiel.veldkamp.  Have you had any success acquiring files from vault using ilogic?  I have been trying to do the same without any results.  I keep getting error 1000 when i run a rule.  The SDK has been helpful for information but I am currently at a standstill for solving this dilemma.

 

 

0 Likes
Message 24 of 26

machiel.veldkamp
Collaborator
Collaborator

Yes!

 

I can't explain all the things right now but I guess you're pretty close if you're getting those vault messages.

Here's the stuff that works if you clean it up.

 

Note: I have a VBA Dictionary filled with paths. So each entry is C:/.../.../FILENAME.ipt

I iterate that dictionary but you can do whatever.

 

oDrawingLocation should be the location where the file is downloaded TO

 

 

Here's the two three main pieces of code:

Imports System.Text
Imports System.IO
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'.Properties

Part of main():

	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. (POTENTIONAL ADD-IN FAULURE)")
		Exit Sub
	End If

	'Dim oStatusDict As New Dictionary(Of String, Integer)
	'Lifecycle States
	'Preliminary 					= LifecyclestateID: 24;	= oStatusDict: 1
	'For Approval 				= LifecyclestateID: ;	= oStatusDict: 2
	'Approved For Construction 	= LifecyclestateID: 31;	= oStatusDict: 3

	ResetVaultCheck : 'Used as a  waypoint in case some files are missing. 

	For i = 0 To oTotalDict.Count - 1
		'oCount = oTotalDict.Values(i)
		Key = oTotalDict.Keys(i)
		dwgPath = Left(Key, Len(Key) - 3) & "dwg"

		SlashPosition = InStrRev(dwgPath, "\")' , - 1)
		Logger.Info("Checking dwgPath: " & dwgPath)
		oDrawingLocation = Left(dwgPath, SlashPosition)

		VaultPartPath = Key.Replace("C:\Company\Vault\", "$/")
		VaultPartPath = VaultPartPath.Replace("\", "/")

		VaultDWGPath = dwgPath.Replace("C:\Company\Vault\", "$/")
		VaultDWGPath = VaultDWGPath.Replace("\", "/")

		Dim VaultDWGPaths() As String = New String() {VaultDWGPath }
		Dim VaultPartPaths() As String = New String() {VaultPartPath }

		Dim wsFiels() As AWS.File = mVltCon.WebServiceManager.DocumentService.FindLatestFilesByPaths(VaultDWGPaths)
		Dim wsFiels2() As AWS.File = mVltCon.WebServiceManager.DocumentService.FindLatestFilesByPaths(VaultPartPaths)

		'Ts file exists in the Vault. 
		Dim DwgFileIt As VDF.Vault.Currency.Entities.FileIteration = New VDF.Vault.Currency.Entities.FileIteration(mVltCon, wsFiels(0)) 		'DWG HERE
		Dim PartFileIt As VDF.Vault.Currency.Entities.FileIteration = New VDF.Vault.Currency.Entities.FileIteration(mVltCon, wsFiels2(0)) 		'PART HERE (IPT/IAM)

		Dim lifeCycleInfo As VDF.Vault.Currency.Entities.FileLifecycleInfo = DwgFileIt.LifecycleInfo

		Dim DWGIsCheckedOut As Boolean = DwgFileIt.IsCheckedOut
		Dim PartIsCheckedOut As Boolean = PartFileIt.IsCheckedOut

		If DWGIsCheckedOut = True
			Logger.Info("CHECKED OUT: " & dwgPath)
			CheckedOutFiles = CheckedOutFiles + 1
		Else If PartIsCheckedOut = True
		Logger.Info("CHECKED OUT: " & Key)
		CheckedOutFiles = CheckedOutFiles + 1
		End If

		If Not lifeCycleInfo.StateId = - 1 'IN VAULT
			If System.IO.File.Exists(dwgPath)
				Logger.Info("YES IN VAULT, YES ON C: " & dwgPath & " Status: " & lifeCycleInfo.StateName)' & " ID:" & lifeCycleInfo.StateId)
				If ILOGIC_RESET_DRAWINGS = True
					Logger.Info("Deleting from C: " & dwgPath)
					DeleteFile(dwgPath)
					Try
						Logger.Info("Getting File From Vault " & dwgPath)
						GetSelectedFiles(DwgFileIt, mVltCon, oDrawingLocation)
					Catch
						Logger.Info("FAILED: GetSelectedFiles for: " & dwgPath)
					End Try
				End If
			End If
			If Not System.IO.File.Exists(dwgPath)
				Logger.Info("YES IN VAULT, NOT ON C: " & dwgPath & " Status: " & lifeCycleInfo.StateName)' & " ID:" & lifeCycleInfo.StateId)
				If Not GetMissingFiles = vbYes
					MissingFiles = MissingFiles + 1
					oMissingFilesDWG = oMissingFilesDWG & dwgPath & vbNewLine
				End If

				Dim fname As String = dwgPath
				Dim file1 As Autodesk.Connectivity.WebServices.File()
				file1 = mVltCon.WebServiceManager.DocumentService.FindLatestFilesByPaths({fname })

				If file1.Length <> 0 Then
					If GetMissingFiles = vbYes
						Logger.Info("Getting File From Vault " & dwgPath)
						GetSelectedFiles(DwgFileIt, mVltCon, oDrawingLocation)
					End If
				End If
			End If
		End If
		If lifeCycleInfo.StateId = - 1 'FILE NOT IN VAULT. 
			' Logger.Info("File not in Vault?: " & dwgPath)
			If System.IO.File.Exists(dwgPath)
				Logger.Info("ON C, NOT IN VAULT: " & dwgPath & " Status: " & lifeCycleInfo.StateName)' & " ID:" & lifeCycleInfo.StateId)
				NotInVault = NotInVault + 1
				oNotInVault = oNotInVault & dwgPath & vbNewLine
			End If
			If Not System.IO.File.Exists(dwgPath)
				'Drawing doesn't exist. Not C nor Vault. 
				Logger.Info("NOT ON C, NOT IN VAULT: " & dwgPath & " Status: " & lifeCycleInfo.StateName)' & " ID:" & lifeCycleInfo.StateId)
			End If
		End If
	Next

 

The sub that gets the files from the Vault:

 

Public Sub GetSelectedFiles(File As Autodesk.Connectivity.WebServices.File, m_connection As VDF.Vault.Currency.Connections.Connection, strTargetFolder As String)
	Logger.Info("Start GetSelectedFiles")

	Dim fileIter As VDF.Vault.Currency.Entities.FileIteration = m_connection.FileManager.GetFilesByIterationIds(New Long() {File.Id }).First().Value
	Dim targetDir As System.IO.DirectoryInfo = New System.IO.DirectoryInfo(strTargetFolder)
	If Not targetDir.Exists Then
		targetDir.Create()
	End If

	Dim downloadSettings As Autodesk.DataManagement.Client.Framework.Vault.Settings.AcquireFilesSettings = New VDF.Vault.Settings.AcquireFilesSettings(m_connection)
	downloadSettings.LocalPath = New Autodesk.DataManagement.Client.Framework.Currency.FolderPathAbsolute(targetDir.FullName)
	downloadSettings.CreateMetaDataFile = True
	downloadSettings.AddFileToAcquire(fileIter, Autodesk.DataManagement.Client.Framework.Vault.Settings.AcquireFilesSettings.AcquisitionOption.Download)
	m_connection.FileManager.AcquireFiles(downloadSettings)
	Logger.Info("Ending GetSelectedFiles")
End Sub

 

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

___________________________
Message 25 of 26

Anonymous
Not applicable

Thank you so much for the response!  I have been struggling with this for quite sometime.  I will make some changes to my code and let you know how it goes.  Thanks again!

Message 26 of 26

maxim.teleguz
Advocate
Advocate

How can I change this to use "FindWhereUsed" Function in vault?

I cant seem to find any good solutions. 

0 Likes