Acquire file based on path from vault.

Acquire file based on path from vault.

Jef_E
Collaborator Collaborator
2,598 Views
3 Replies
Message 1 of 4

Acquire file based on path from vault.

Jef_E
Collaborator
Collaborator

Hi,

 

I'm trying to get a specific file based on the path from vault. I find loads of acquire samples but never how to select a specific file based on the path. Could someone please show me a sample of the step that I need to make to pass a value to these methods? I think I need to work with the "Download assembly" method.

 

Code Source

 

 

' VB
Imports VDF = Autodesk.DataManagement.Client.Framework
 
Public Sub DownlodFiles(fileIters As ICollection(Of VDF.Vault.Currency.Entities.FileIteration))
       ' download individual files to a temp location
       Dim settings As New VDF.Vault.Settings.AcquireFilesSettings(m_conn)
       settings.LocalPath = New VDF.Currency.FolderPathAbsolute("c:\temp")
       For Each fileIter As VDF.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 As VDF.Vault.Currency.Entities.FileIteration)
       ' download the latest version of the assembly to working folders
       Dim settings As New VDF.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 As VDF.Vault.Currency.Entities.FileIteration, _
    parentWindowHandle As IntPtr)
       ' pop up the Get/Checkout dialog
       Dim settings As New VDF.Vault.Forms.Settings.InteractiveAcquireFileSettings( _
           m_conn, parentWindowHandle, "Download files")
       settings.AddEntityToAcquire(fileIter)
 
       VDF.Vault.Forms.Library.AcquireFiles(settings)
End Sub

 

 



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes
2,599 Views
3 Replies
Replies (3)
Message 2 of 4

junyi_zhu
Autodesk
Autodesk

If you have the vault path, you can use the API below to get the file proxy, which include the file IDs.

 

public File[] FindLatestFilesByPaths(
System.string[] filePaths
)



Junyi Zhu

Message 3 of 4

Jef_E
Collaborator
Collaborator

Hi, @junyi_zhu thanks for the reply, I have a problem implementing the suggestion you made ( I'm new to this and the API looks like a maze to me, compared to the Autodesk Inventor API )

 

How do I access the findlatestfilesbypath method?

 

Here is my code so far, but I can't find the findlatestfilesbypath method on the ACW.DocumentService Object.

 

 

Imports ACW = Autodesk.Connectivity.WebServices
Imports VDF = Autodesk.DataManagement.Client.Framework

Public Class SyncFiles

    Public Sub New()

        ' This call is required by the designer.
        InitializeComponent()

        ' Login into vault
        Dim oLogin As VDF.Vault.Results.LogInResult
        oLogin = VDF.Vault.Library.ConnectionManager.LogIn("localhost", "Vault", "Administrator", "", VDF.Vault.Currency.Connections.AuthenticationFlags.Standard, Nothing)

        ' Check if the login was succesfull
        If Not oLogin.Success Then

            MsgBox("Failed to login to vault.", MsgBoxStyle.Exclamation, "Vault login error")
            Me.DialogResult = DialogResult.Abort

        End If

        ' Get the connection made by the login
        Dim oConnection As VDF.Vault.Currency.Connections.Connection
        oConnection = oLogin.Connection

        ' Get the file by path
        Dim oFile As ACW.File
        oFile = ACW.DocumentService

    End Sub

End Class

 



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes
Message 4 of 4

JamieVJohnson2
Collaborator
Collaborator

Here is how I get files from vault.  It may not be as elegant as what you are attempting to do, but it works for me.

 

GetVaultedFileData (I store my acquired file and its vault information in a custom object called VaultedFile)

GetRelatedFilesFromVault (uses the search engine to find vault data based on file name without path)  I had to add a qualifier to weed out vault search oddities.

GetFileFolders (this will get the folder from its Folder ID for each found in vault file)

GetFolderPath (this turns a vault folder path into a local hd folder path)

VaultWorkingFolder - is a constant for my user's root local path for their working folder for me it is "C:\VaultWorkingFolder"

 

Hope this helps.

 

    Public Sub GetVaultedFileData(fi As System.IO.FileInfo)
        Try
            WorkFile = fi
            Dim vFile As VWS.File = Nothing
            Dim files As List(Of VWS.File) = GetRelatedFilesFromVault(fi)
            Dim folders As List(Of VWS.Folder) = GetFileFolders(files)
            For Each file As VWS.File In files
                For Each folder As VWS.Folder In folders
                    If folder.Id = file.FolderId Then
                        Dim strPath As String = GetFolderPath(folder) & "\" & file.VerName
                        If fi.FullName = strPath Then
                            VaultFile = file
                            VaultFolder = folder
                            Exit For
                        End If
                    End If
                Next
            Next
        Catch ex As Exception
            Dim eh As New ErrorHandler(ex)
            eh.HandleIt()
        End Try
    End Sub

    Public Function GetRelatedFilesFromVault(fi As System.IO.FileInfo) As List(Of VWS.File)
        Dim files As New List(Of VWS.File)
        Dim scs As New List(Of VWS.SrchCond)
        Dim sc As New VWS.SrchCond
        With sc
            .PropDefId = 9
            .SrchOper = 1
            .SrchTxt = fi.Name
            .PropTyp = VWS.PropertySearchType.SingleProperty
            .SrchRule = VWS.SearchRuleType.Must
        End With
        scs.Add(sc)
        Dim srs As New List(Of VWS.SrchSort)
        Dim fIDs As New List(Of Long)
        Dim bm As String = String.Empty
        Dim ss As New VWS.SrchStatus
        Dim intFilesProcessed As Integer = 0
        Do
            Try
                Dim foundfiles() As VWS.File = wsm.DocumentService.FindFilesBySearchConditions(scs.ToArray, srs.ToArray, fIDs.ToArray, True, True, bm, ss)
                If foundfiles IsNot Nothing Then 'not so fast, vault is returning bogus entries, we need to compare the files returned ourselves.
                    For Each foundFile As VWS.File In foundfiles
                        intFilesProcessed += 1
                        If foundFile.Name = fi.Name Then
                            files.Add(foundFile)
                        End If
                    Next
                    'files.AddRange(foundfiles)
                End If
            Catch ex As Exception
                Dim eh As New ErrorHandler(ex)
                eh.HandleIt()
            End Try
        Loop Until ss.TotalHits = intFilesProcessed
        Return files
    End Function

    Public Function GetFileFolders(files As List(Of VWS.File)) As List(Of VWS.Folder)
        Dim folderIDs As New List(Of Long)
        For Each file As VWS.File In files
            If folderIDs.Contains(file.FolderId) = False Then
                folderIDs.Add(file.FolderId)
            End If
        Next
        Dim folders As New List(Of VWS.Folder)
        folders.AddRange(wsm.DocumentService.FindFoldersByIds(folderIDs.ToArray))
        Return folders
    End Function

    Public Function GetFolderPath(folder As VWS.Folder) As String
        Dim strFolderPath As String = String.Empty
        If folder.FullUncName IsNot Nothing Then
            strFolderPath = folder.FullUncName
        ElseIf folder.FullName IsNot Nothing Then
            strFolderPath = folder.FullName
        End If
        Return strFolderPath.Replace("$", VaultWorkingFolder).ToString.Replace("/", "\")
    End Function
Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes