Read a list of files from excel and download/get them from vault using ilogic

Read a list of files from excel and download/get them from vault using ilogic

phani.gampala
Contributor Contributor
1,028 Views
15 Replies
Message 1 of 16

Read a list of files from excel and download/get them from vault using ilogic

phani.gampala
Contributor
Contributor

Hello everyone,

I have automated configuration that replaces a lot of parts from a excel file. All these parts are required to be in the local space of the user. I need to add a rule to my assembly that reads the list of parts from excel and downloads them from vault into the local space of the user. I am not familiar with vault API and am not good at VBA. I just started to write some complicated coding using Inventor API. Is it possible to achieve this...It is crucial for the automated model to work for all the users...

Any suggestion or direction is much appreciated. 

Regards,

Phani.

0 Likes
1,029 Views
15 Replies
Replies (15)
Message 2 of 16

johnsonshiue
Community Manager
Community Manager

Hi! I am not sure if this is related. Please take a look at the following thread.

 

https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/get-file-from-vault/td-p/5514721

 

Many thanks!

 



Johnson Shiue (johnson.shiue@autodesk.com)
Software Test Engineer
0 Likes
Message 3 of 16

phani.gampala
Contributor
Contributor

Thanks for the response @johnsonshiue,

I did not quite follow the conversation in that link. I think I have to create a dll file to mentiona reference in ilogic to access vault API, but I'm new to all of that!

0 Likes
Message 4 of 16

tyler.warner
Advocate
Advocate

@phani.gampala this is some iLogic code written in VB.NET that would get the files from Vault based on the cells in the Excel sheet. This is setup to be run in Inventor after it is logged into Vault. Those settings can be adjusted.

 

Additional Vault questions will get better response on the Vault Customization Forum (link) instead of this one.

 

 

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

Imports Autodesk.Connectivity.WebServices
Imports ACW = Autodesk.Connectivity.WebServices
Imports ACWT = Autodesk.Connectivity.WebServicesTools
Imports VB = Connectivity.Application.VaultBase
Imports VDF = Autodesk.DataManagement.Client.Framework

Sub Main
		
	Dim oExcelList As ArrayList
	oExcelList = GoExcel.CellValues("C:\MY_WORKSPACE\FilesToGet.xlsx", "Sheet1", "A1", "A3")
	
	' Ex: "C:\MY_WORKSPACE\File.idw"
	For Each FullFileNameWithExtension In oExcelList
		AcquireVaultFile(FullFileNameWithExtension)
	Next	
		
End Sub


Sub AcquireVaultFile(oFileName As String)
	
    Dim oVaultConn As VDF.Vault.Currency.Connections.Connection = VB.ConnectionManager.Instance.Connection

    If oVaultConn Is Nothing Then
        MsgBox("Not Logged In to Vault! Login first & repeat executing this rule.")
    End If

    Try
		' "C:\MY_WORKSPACE\" = Project Specified Working Folder.
        Dim oTemplateVaultPath As String = oFileName.Replace("C:\MY_WORKSPACE\", "$/")
        oTemplateVaultPath = oTemplateVaultPath.Replace("\", "/")
        Dim oVaultPaths() As String = New String() {oTemplateVaultPath}
				
        Dim oWebServFiles() As ACW.File = oVaultConn.WebServiceManager.DocumentService.FindLatestFilesByPaths(oVaultPaths)
		
        oFileIteration = New VDF.Vault.Currency.Entities.FileIteration(oVaultConn, oWebServFiles(0))
		
        Dim oVaultSettings As New VDF.Vault.Settings.AcquireFilesSettings(oVaultConn)
        oVaultSettings.DefaultAcquisitionOption = VDF.Vault.Settings.AcquireFilesSettings.AcquisitionOption.Download
        oVaultSettings.OptionsRelationshipGathering.FileRelationshipSettings.VersionGatheringOption = VDF.Vault.Currency.VersionGatheringOption.Latest
        oVaultSettings.AddFileToAcquire(oFileIteration, oVaultSettings.DefaultAcquisitionOption)

        Dim oVaultResults As VDF.Vault.Results.AcquireFilesResults = oVaultConn.FileManager.AcquireFiles(oVaultSettings)
    Catch ex As Exception
        MsgBox("Could not download file: " & vbNewLine & oFileName)
	End Try
	
End Sub

 

 

If this solved your problem or answered your question, please click ACCEPT SOLUTION.
If this helped you, please click LIKE.
0 Likes
Message 5 of 16

phani.gampala
Contributor
Contributor

Thank you very much @tyler.warner. The code is running but comes up with the error message /exception message in the try catch loop always. It is unable to find any part in vault for reasons I don't understand.  

0 Likes
Message 6 of 16

tyler.warner
Advocate
Advocate

If you're including this in an add-in, then step thru the code while debugging to see which line errors out.

 

If you're doing this in iLogic, in the try catch loop, you can either add a message box between lines or add logger info. Let me know where the error is occurring for you & we can correct it.

If this solved your problem or answered your question, please click ACCEPT SOLUTION.
If this helped you, please click LIKE.
0 Likes
Message 7 of 16

phani.gampala
Contributor
Contributor

Hi @tyler.warner,

Thanks for the response. The rule runs through and gives "could not download file" every single time.

However, when I tested with a msgbox as in the screenshot attached. Test Msgbox ("here") shows up at every line of code except when it is placed after the acquire files line (see screenshot). 

0 Likes
Message 8 of 16

tyler.warner
Advocate
Advocate

So the acquire files is the part that isn't working. I'm guessing it has something to do with the file name or file location.

 

The example above has the full file name with the path (Ex: "C:\MY_WORKSPACE\File.idw) included in the cell specifying which drawing you want (lines 16 & 17). You can adjust that if needed.

 

The change from the working folder location to the Vault location (lines 33-35) could be causing issues. For clarity, the "$/" stands for the "Project Explorer" location in your Vault (line 34). In the working folder, the slashes are a different direction than the slashes for the Vault location (line 35) so the command swaps those.

 

Verify some of those things. If still not working then maybe post your code & excel file.

 

If this solved your problem or answered your question, please click ACCEPT SOLUTION.
If this helped you, please click LIKE.
0 Likes
Message 9 of 16

phani.gampala
Contributor
Contributor

Hi @tyler.warner,

Thanks for the explanation. I have verified those parts of the code. I'm getting the same result. I have attached the code and the excel file like you mentioned. I think , I'm missing something basic. Will the code check for the file through different folders under Project explorer in vault. I have also tried putting a file directly under Project explorer in vault and tried to download that with code but it did not work.

 

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 "Autodesk.DataManagement.Client.Framework.dll"
AddReference "Connectivity.Application.VaultBase.dll"
AddReference "Autodesk.Connectivity.WebServices.dll"


Sub Main
Dim excelFilelocation As String
excelFilelocation = "L:\Phani\RC REPLACEMENT.xlsx"
Dim oExcelList As ArrayList
oExcelList = GoExcel.CellValues(excelFilelocation, "Sheet3", "A1", "A3")

' Ex: "C:\MY_WORKSPACE\File.idw"
For Each FullFileNameWithExtension In oExcelList
AcquireVaultFile(FullFileNameWithExtension)
Next

End Sub


Sub AcquireVaultFile(oFileName As String)

Dim oVaultConn As VDF.Vault.Currency.Connections.Connection = VB.ConnectionManager.Instance.Connection

If oVaultConn Is Nothing Then
MsgBox("Not Logged In to Vault! Login first & repeat executing this rule.")
End If
Try
' "C:\MY_WORKSPACE\" = Project Specified Working Folder.
Dim oTemplateVaultPath As String = oFileName.Replace("C:\Users\phanig\Documents\Vault\", "$/")
oTemplateVaultPath = oTemplateVaultPath.Replace("\", "/")
Dim oVaultPaths() As String = New String() {oTemplateVaultPath}

Dim oWebServFiles() As AWS.File = oVaultConn.WebServiceManager.DocumentService.FindLatestFilesByPaths(oVaultPaths)

Dim oFileIteration As VDF.Vault.Currency.Entities.FileIteration = New VDF.Vault.Currency.Entities.FileIteration(oVaultConn, oWebServFiles(0))
Dim oVaultSettings As New VDF.Vault.Settings.AcquireFilesSettings(oVaultConn)
oVaultSettings.DefaultAcquisitionOption = VDF.Vault.Settings.AcquireFilesSettings.AcquisitionOption.Download
oVaultSettings.OptionsRelationshipGathering.FileRelationshipSettings.VersionGatheringOption = VDF.Vault.Currency.VersionGatheringOption.Latest
oVaultSettings.AddFileToAcquire(oFileIteration, oVaultSettings.DefaultAcquisitionOption)

Dim oVaultResults As VDF.Vault.Results.AcquireFilesResults = oVaultConn.FileManager.AcquireFiles(oVaultSettings)
Catch ex As Exception
MsgBox("Could not download file: " & vbNewLine & oFileName)
End Try

End Sub

0 Likes
Message 10 of 16

tyler.warner
Advocate
Advocate

Hey @phani.gampala try to correct your file names & file locations per instructions below.

Right now, the way they are in your code & Excel file, it will not work as you can tell with testing.

 

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

Dim excelFilelocation As String

     ' (This should be where the Excel file is stored on your computer)
excelFilelocation = "L:\Phani\RC REPLACEMENT.xlsx"
Dim oExcelList As ArrayList
oExcelList = GoExcel.CellValues(excelFilelocation, "Sheet3", "A1", "A3")

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

 

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

' "C:\MY_WORKSPACE\" = Project Specified Working Folder.

     ' (L:\Phani\RC REPLACEMENT.xlsx\0092230.ipt   (from Excel) will not be changed..... here's the issue)

     ' ()

     ' (If the file   0092230.ipt   is stored in this folder   C:\Users\phanig\Documents\Vault\   )

     ' (Then the Excel cell needs to contain   C:\Users\phanig\Documents\Vault\0092230.ipt   )

     ' (Then the below lines will change it to search in your Vault for   Project Explorer/0092230.ipt   )
Dim oTemplateVaultPath As String = oFileName.Replace("C:\Users\phanig\Documents\Vault\", "$/")
oTemplateVaultPath = oTemplateVaultPath.Replace("\", "/")
Dim oVaultPaths() As String = New String() {oTemplateVaultPath}

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

If this solved your problem or answered your question, please click ACCEPT SOLUTION.
If this helped you, please click LIKE.
0 Likes
Message 11 of 16

phani.gampala
Contributor
Contributor

Thank you @tyler.warner, the code works well. Thank you for the explanation.

That was a silly mistake from me. Is there a way I can search through folders for each part instead of having to mention the path for each file? We have numerous folders in vault which has made this process complicated. Lastly, how can I learn Vault API and learn to use it in ilogic?

0 Likes
Message 12 of 16

ls-4453
Enthusiast
Enthusiast

If you follow the instructions on the Autodesk website, you can install the Vault SDK and get access to the Vault SDK Help File.

 

https://knowledge.autodesk.com/support/vault-products/learn-explore/caas/sfdcarticles/sfdcarticles/H...

 

You probably want to use FindFilesBySearchConditions.

 

https://justonesandzeros.typepad.com/blog/2012/09/finding-by-search-conditions.html

 

The example searches by the property "CheckoutUserName", you want to use "ClientFileName".

 

Dim filePropDefs As ACW.PropDef()
filePropDefs = oVaultConn.WebServiceManager.PropertyService.GetPropertyDefinitionsByEntityClassId("FILE")

Dim filenamePropDef As ACW.PropDef
filenamePropDef = filePropDefs.Single(Function(n) n.SysName = "ClientFileName")
0 Likes
Message 13 of 16

ls-4453
Enthusiast
Enthusiast

This code should work.

 

 

' VB.NET

Dim filePropDefs As ACW.PropDef() = _

    oVaultConn.WebServiceManager.PropertyService.GetPropertyDefinitionsByEntityClassId("FILE")

Dim fileNamePropDef As ACW.PropDef = _

    filePropDefs.[Single](Function(n) n.SysName = "ClientFileName")

 

' SrchOper 3 => equals

Dim fileNameToFind As New ACW.SrchCond() With { _

       .PropDefId = fileNamePropDef.Id, _

       .PropTyp = ACW.PropertySearchType.SingleProperty, _

       .SrchOper = 3, _

       .SrchRule = ACW.SearchRuleType.Must, _

       .SrchTxt = "YOUR FILE NAME GOES HERE" _

}

 

Dim bookmark As String = String.Empty

Dim status As ACW.SrchStatus = Nothing

Dim totalResults As New List(Of ACW.File)()

While status Is Nothing OrElse totalResults.Count < status.TotalHits

       Dim results As ACW.File() = _

          oVaultConn.WebServiceManager.DocumentService.FindFilesBySearchConditions( _

           New ACW.SrchCond() {fileNameToFind}, _

           Nothing, Nothing, False, True, bookmark, _

              status)

 

       If results IsNot Nothing Then

              totalResults.AddRange(results)

       Else

              Exit While

       End If

End While

' total results now has the results

 

0 Likes
Message 14 of 16

phani.gampala
Contributor
Contributor

Hi @ls-4453,

Thank you very much. The code runs without errors but does not download the file. I'm missing something here. 

 

' VB.NET
Dim oVaultConn As VDF.Vault.Currency.Connections.Connection = VB.ConnectionManager.Instance.Connection
Dim filePropDefs As ACW.PropDef() = oVaultConn.WebServiceManager.PropertyService.GetPropertyDefinitionsByEntityClassId("FILE")
Dim fileNamePropDef As ACW.PropDef = filePropDefs.[Single](Function(n) n.SysName = "ClientFileName")

' SrchOper 3 => equals
Dim fileNameToFind As New ACW.SrchCond() With { .PropDefId = fileNamePropDef.Id, .PropTyp = ACW.PropertySearchType.SingleProperty, _
.SrchOper = 3, .SrchRule = ACW.SearchRuleType.Must, .SrchTxt = "0108788.ipt"}

Dim bookmark As String = String.Empty

Dim status As ACW.SrchStatus = Nothing

Dim totalResults As New List(Of ACW.File)()

While status Is Nothing OrElse totalResults.Count < status.TotalHits

Dim results As ACW.File() = oVaultConn.WebServiceManager.DocumentService.FindFilesBySearchConditions( New ACW.SrchCond() {fileNameToFind}, _
Nothing, Nothing, False, True, bookmark, status)

If results IsNot Nothing Then
totalResults.AddRange(results)
Else
Exit While
End If
End While

' total results now has the results

  

0 Likes
Message 15 of 16

ls-4453
Enthusiast
Enthusiast

Yes, that code only gets you a list of Vault files that match the search. You need to use the Vault API to download them (https://justonesandzeros.typepad.com/blog/2013/05/how-to-acquire-files.html).

0 Likes
Message 16 of 16

ls-4453
Enthusiast
Enthusiast

This code should do what you want.

 

 

Dim oSettings As VDF.Vault.Settings.AcquireFilesSettings
oSettings = New VDF.Vault.Settings.AcquireFilesSettings(oVaultConn, False)
For Each file As ACW.File In totalResults
	Dim fileToDownload As VDF.Vault.Currency.Entities.FileIteration
	fileToDownload = New VDF.Vault.Currency.Entities.FileIteration(oVaultConn, File)
	oSettings.AddFileToAcquire(fileToDownload, VDF.Vault.Settings.AcquireFilesSettings.AcquisitionOption.Download)
Next

Dim oAcquireFilesResults As VDF.Vault.Results.AcquireFilesResults
oSettings.OptionsRelationshipGathering.FileRelationshipSettings.IncludeChildren = True
oSettings.OptionsRelationshipGathering.FileRelationshipSettings.RecurseChildren = True
oSettings.OptionsRelationshipGathering.FileRelationshipSettings.VersionGatheringOption = VDF.Vault.Currency.VersionGatheringOption.Latest
oSettings.OptionsResolution.OverwriteOption = VDF.Vault.Settings.AcquireFilesSettings.AcquireFileResolutionOptions.OverwriteOptions.NoOverwrite

oAcquireFilesResults = oVaultConn.FileManager.AcquireFiles(oSettings)

 

 

 

 

0 Likes