Download files from vault using iLogic

Download files from vault using iLogic

Koekepeerke
Advocate Advocate
695 Views
1 Reply
Message 1 of 2

Download files from vault using iLogic

Koekepeerke
Advocate
Advocate

Hello everyone, 

 

i'm working on an external rule that gets files from the vault to workspace based on only the filename (no path) so they can then be applied for replacement in configurators for example. My knowledge on Vault's API is still very very limited so i basically just started to paste bits and pieces of code from the forums/internet together and to my disbelief i actually got it working. the only problem is it's very slow! I think most time is spent getting the vault path from the filename, acquiring the file is quite fast. 

 

Does anybody know if i'm maybe not using the most efficient method? or maybe my code is just very messy and it needs some proper cleaning/reconstructing to operate better. Any advice or help would be appreciated! I would like for it to run smoothly so we aren't dependent on external add-ins, libraries or .dlls to acces our vault files through iLogic. This way we have a standalone function.

 

My current rule:

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

 

Dim results1 As VDF.Vault.Results.LogInResult = VDF.Vault.Library.ConnectionManager.LogIn("vault2301", "NXTdimVault", "Administrator", "", VDF.Vault.Currency.Connections.AuthenticationFlags.WindowsAuthentication, Nothing)
If Not results1.Success Then
    MsgBox("Error1")
End If

Dim connection As VDF.Vault.Currency.Connections.Connection = Nothing
connection = results1.Connection
		
Dim conditions As Autodesk.Connectivity.WebServices.SrchCond()
ReDim conditions(0)

Dim nameOfFile As String = "AE0110931.ipt" '< For now i just inserted the filename but i will do this through rule arguments when i have it running properly.

Dim Defs As Autodesk.Connectivity.WebServices.PropDef() = connection.WebServiceManager.PropertyService.GetPropertyDefinitionsByEntityClassId("FILE")
Dim Prop As Autodesk.Connectivity.WebServices.PropDef = Nothing


For Each def As Autodesk.Connectivity.WebServices.PropDef In Defs
	If def.DispName = "File Name" Then
		Prop = def
		Exit For
	End If
Next def


Dim searchCondition As Autodesk.Connectivity.WebServices.SrchCond = New Autodesk.Connectivity.WebServices.SrchCond With { _
   .PropDefId = Prop.Id, _
   .PropTyp = Autodesk.Connectivity.WebServices.PropertySearchType.SingleProperty, _
   .SrchOper = 5, _
   .SrchTxt = nameOfFile _
} 

Dim FileList As List(Of Autodesk.Connectivity.WebServices.File) = New List(Of Autodesk.Connectivity.WebServices.File)()
Dim sBookmark As String = String.Empty
Dim Status As Autodesk.Connectivity.WebServices.SrchStatus = Nothing

conditions(0) = searchCondition

While (Status Is Nothing OrElse FileList.Count < Status.TotalHits)

	Dim files As Autodesk.Connectivity.WebServices.File() = connection.WebServiceManager.DocumentService.FindFilesBySearchConditions(conditions, Nothing, Nothing, True, True, sBookmark, Status)

	If (Not files Is Nothing) Then
		FileList.AddRange(files)
	End If

End While

For i = 0 To FileList.Count - 1
	If FileList.Item(i).Name = nameOfFile Then
		iIndex = i
		bItemFound = True
		Exit For
	End If
Next

Dim fileke As Autodesk.Connectivity.WebServices.File = FileList.Item(iIndex)
Dim filepaths As Autodesk.Connectivity.WebServices.FilePath() = connection.WebServiceManager.DocumentService.FindFilePathsByNameAndChecksum(fileke.Name, fileke.Cksum)

Dim pad As String = filepaths(0).Path
'MsgBox(pad)
Dim VaultPath As String = pad

Dim folderpath As String

folderpath = VaultPath.Replace("$/", "C:\Workspace\NXTdimVault\")
folderpath = folderpath.Replace("/", "\")

Dim workspacePad As String = folderpath

SplitPath = folderpath.Split("\")
folderpath = SplitPath(0) & "\"
For i = 1 To SplitPath.Length - 2
	folderpath = folderpath & SplitPath(i) & "\"
Next


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

'oSettings.LocalPath = New VDF.Currency.FolderPathAbsolute(folderpath)
oSettings.LocalPath = New Autodesk.DataManagement.Client.Framework.Currency.FolderPathAbsolute(folderpath)
'Autodesk.DataManagement.Client.Framework.Vault.Currency.FolderPathAbsolute

oSettings.AddFileToAcquire(mFileIt, VDF.Vault.Settings.AcquireFilesSettings.AcquisitionOption.Download)




Dim oResults As VDF.Vault.Results.AcquireFilesResults = connection.FileManager.AcquireFiles(oSettings)

'oResults.FileResults

ThisApplication.Documents.Open(workspacePad)

Regards,

Jeremy

 

 

 

 

 

 

 

 

 

0 Likes
696 Views
1 Reply
Reply (1)
Message 2 of 2

jani_karjalainenJFQAG
Participant
Participant

I'm currently working on something same like you were in this post. How long does it take to open the file with this code? If I try it takes over 5 minutes and it still has not opened

0 Likes