How to Acquire Files

Downloading and checking-out is so last year.  The fashionable Vault API developer acquires their files.  It has more style and class.  Also, DocumentService.DownloadFile and DocumentService.CheckoutFile are no more in the 2014 API.  So that kind of forces the issue.  Connection.FileManager.AcquireFiles is the replacement.  I’ll go over the architectural reason for the change in a later article.


Benefits of AcquireFiles

Yes, it’s a pain to have to update your code, but let me go over the benefits before you get too distraught. 

  • Downloads files to the working folder by default.
  • Automatically handles large files.
  • Automatically repairs broken references for known CAD file types.
  • Can download entire assemblies in one call.
  • Multi-thread download.  It’s about 2x quicker when downloading an assembly.
  • Get/checkout dialog available.
  • Automatically sets file attributes, such as read-only and create date.

The only disadvantage that I have come across is that you can’t read a file directly into memory.  You always acquire to a location on disk.  The workaround is to acquire to a temp location, read the file to memory, then delete the temp file.


Here is some sample code.

// C#

using VDF = Autodesk.DataManagement.Client.Framework;

 

public void DownlodFiles(ICollection<VDF.Vault.Currency.Entities.FileIteration> fileIters)

{

    // download individual files to a temp location

    VDF.Vault.Settings.AcquireFilesSettings settings =

        new VDF.Vault.Settings.AcquireFilesSettings(m_conn);

    settings.LocalPath = new VDF.Currency.FolderPathAbsolute(@"c:\temp");

    foreach (VDF.Vault.Currency.Entities.FileIteration fileIter in fileIters)

    {

        settings.AddFileToAcquire(fileIter,

            VDF.Vault.Settings.AcquireFilesSettings.AcquisitionOption.Download);

    }

 

    VDF.Vault.Results.AcquireFilesResults results = m_conn.FileManager.AcquireFiles(settings);

}

 

public void DownloadAssembly(VDF.Vault.Currency.Entities.FileIteration topLevelAssembly)

{

    // download the latest version of the assembly to working folders

    VDF.Vault.Settings.AcquireFilesSettings settings =

        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);

 

    VDF.Vault.Results.AcquireFilesResults results =

        m_conn.FileManager.AcquireFiles(settings);

}

 

public void DownloadDialog(VDF.Vault.Currency.Entities.FileIteration fileIter,

    IntPtr parentWindowHandle)

{

    // pop up the Get/Checkout dialog

    VDF.Vault.Forms.Settings.InteractiveAcquireFileSettings settings =

        new VDF.Vault.Forms.Settings.InteractiveAcquireFileSettings(

            m_conn, parentWindowHandle, "Download files");

    settings.AddEntityToAcquire(fileIter);

 

    VDF.Vault.Forms.Library.AcquireFiles(settings);

}

' 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


Comments

21 responses to “How to Acquire Files”

  1. scott moyse Avatar
    scott moyse

    I love the way you have been writing these last few posts by the way Doug. Adding a bit of pizzazz! good work

  2. hello Doug,
    It can download entire assemblies in one call, but i’m curious if it is possible todownload all drawings from assembly reference documents in one call?

  3. You are referring to .idw files on an Inventor assembly? Yes you can download those as part of the assembly download. One of the various AcquireFilesSettings allows you to specify the FileRelationshipGatheringSettings. If IncludeRelatedDocumentation is set to true, it should download the drawing files.

  4. Doug
    love the examples.
    Is it possible to check out the entire assembly with this method. My code will download iam, ipt and idw files but if i use the checkout option it only checks out the iam file.
    regards Wayne

  5. You need to set DefaultAcquisitionOption on the settings object.

  6. Doug
    thanks for the reply.
    played around with the defaultAcquisitionOption but not sure how the AddFileToAcquire actually uses this as it requires a an acquisitionOption as the second parameter. It did check out the assy and parts but did not download them. Im looking at checking out and downloading all objects in 1 easy step.
    here is my code – obviously not getting something
    Settings.LocalPath = fldrPath
    Settings.OptionsRelationshipGathering.FileRelationshipSettings.IncludeChildren = True
    Settings.OptionsRelationshipGathering.FileRelationshipSettings.RecurseChildren = True
    Settings.OptionsRelationshipGathering.FileRelationshipSettings.IncludeRelatedDocumentation = True
    Settings.OptionsRelationshipGathering.FileRelationshipSettings.VersionGatheringOption = Autodesk.DataManagement.Client.Framework.Vault.Currency.VersionGatheringOption.Latest
    Settings.DefaultAcquisitionOption = VDF.Vault.Settings.AcquireFilesSettings.AcquisitionOption.Checkout
    Settings.AddFileToAcquire(oFileIteration, Autodesk.DataManagement.Client.Framework.Vault.Settings.AcquireFilesSettings.AcquisitionOption.Checkout)
    Dim results As VDF.Vault.Results.AcquireFilesResults = vaultConnection.FileManager.AcquireFiles(Settings)

  7. Hi doug
    Got back onto this after I had decided to use the downloaddialogue method for awhile. What I would like to do is to determine the files that will be wrapped up with the acquirefiles prior to actually downloading/checking them out. The reason is we would like to change the state of the corresponding files back to “draft” before they are checked out by the user. I cant do it after the case because it wont let me change the state when the files are checked-out. I was hoping the “noaction” option may stil provide a result list that i could use to pre-process the files and change their state. Any suggestions.

  8. I have been reading the documentation covering aquirefileExtensibilityOptions and am lost!! Is there any examples of how to use the preAcquire event. I was wondering if this could possibly be a solution for preprocessing files

  9. Offhand, I don’t have any sample code for you. In general, I suggest not making any updates within an event. The reason is that your actions may affect the operation in progress. It’s like trying to fix a table while standing on the table.
    Here is the order of operations that I suggest:
    1. Run AcquireFiles in noAction mode
    2. In your event handler, read all the files being updated and store them in a list.
    3. AcquireFiles exists
    4. Go through your list and perform the needed operations.
    5. Run AcquireFiles again to check out the files. No event handlers are needed this time.

  10. thanks doug. I was trying the noAction mode to try and identify what documents would be acquired prior to acyually doing it. Everytime i tried it i would get no acquireResults back so I gave up and have resorted to the getLatestAssociatedFileePathsByMasterIds method.

  11. Hi Doug,
    nice sample, but what about Inventor standard parts?
    How do I get out of the vault?

  12. If you are download an assembly, I would expect the standard parts automatically come down.
    If you just want to grab all the standard parts on their own, I think you have to interrogate the IPJ to look-up the Vault paths to the library folders.

  13. Larry Daubenspeck Avatar
    Larry Daubenspeck

    Hi Doug,
    All the examples I can find use userpassword credentials. How do you use WinAuthCredentials?

  14. For Vault 2013 and earlier…
    Instead of creating a new UserPasswordCredentials object, you create a new WinAuthCredentials object. After that,everything is the same. You pass the credentials object into the constructor for WebServiceManager.
    The code would look something like this…
    UserPasswordCredentials cred = new UserPasswordCredentials(“theServer”, “theVault”);
    WebServiceManager mgr = new WebServiceManager(cred);
    For Vault 2014 and later…
    For a non UI login, use Autodesk.DataManagement.Client.Framework.Vault.Library.ConnectionManager.LogIn(..)
    To prompt the user to login, use
    Autodesk.DataManagement.Client.Framework.Vault.Forms.LogIn(..)

  15. Davide Orlando Avatar
    Davide Orlando

    Hi Doug,
    i use the param VersionGatheringOption and set it to Latest, but sometimes the AcquireFiles download an old version of the file.
    What is the reason?
    Thanks..

  16. That option is for downloading related files. It does not apply to the FileIteration that you provide as the input. In that case, it download the version on that FileIteration.
    Call FileService.GetLatestFilesByIterationIds to get the latest version of the file and use that to start the download.
    If that’s not the solution to your problem, then I suggest posting to the Vault Customization group. That way it’s easier for you to post sample code, screen shots, etc.
    http://forums.autodesk.com/t5/Vault-Customization/bd-p/301

  17. Johnny Kuhn Avatar
    Johnny Kuhn

    I am sorry but I have to say, this is the next big step backward. Removing the most important function “DownloadFile” and replacing it with pseudo intelligent layers. And I am not even talking about noobish implementation of the new API layer. Vault web services API was one of the few if not the only clear API within Autodesk universe. 2015 rip vault API. Really sad.

  18. Hi Doug,
    In my external program, user select a row in the VaultBrowserControl. Selected row has EntityClass.Id == “FILE” (it can be a file or a file link).

    This is my code to acquire the file from Vault:

    VDF.Vault.Settings.AcquireFilesSettings settings = new VDF.Vault.Settings.AcquireFilesSettings(conn);
    settings.LocalPath = new VDF.Currency.FolderPathAbsolute(tmpPath);
    settings.AddFileToAcquire(fileIter, VDF.Vault.Settings.AcquireFilesSettings.AcquisitionOption.Download);

    VDF.Vault.Results.AcquireFilesResults afResults = conn.FileManager.AcquireFiles(settings);

    No error, the file is downloaded, but when “fileIter” is a file link (not just the file, in this case it works) the file name in the LocalPath is truncated in its first character.
    I forgot to set some option ?
    Thank you.

  19. That does not sound like intended behavior. If you are an ADN member you should log the issue with them. Otherwise you can post the issue on the Vault API discussion group http://forums.autodesk.com/t5/vault-customization/bd-p/301
    In the meantime, the workaround is to fix the file name after the download is complete.

  20. Hi Doug:
    I have a problem with working folder.
    If I set the working folder anything other than the default working folder and get the file from vault as it explain here and a few other pages, all the file get downloaded properly. But when I open the assembly in Inventor, Inventor tries to find the file in the folder that was created.
    For example:
    If in D:\Vault\Folder1, there are ASM1.ism that has part1.ipt, part2.ipt and while downloading, I specify it to be downloaded to D:\Vault\Folder2, the three files will be downloaded to the new folder and every thing seems to be ok. However, when I open the assembly file in the new folder (Folder2), it still opens the parts in Folder1.
    If I use “Autodesk Vault Basic” that comes with Inventor, it does it correctly and update the reference, but using API, I had no success.
    Here is my code:
    Dim fname As String = dlg1.LookIn.Text + “/” + dlg1.FileName.Text
    Dim file1 As Autodesk.Connectivity.WebServices.File()
    file1 = connection.WebServiceManager.DocumentService.FindLatestFilesByPaths({fname})
    If file1.Length <> 0 Then
    Dim oFileIteration As VDF.Vault.Currency.Entities.FileIteration = Nothing
    oFileIteration = New VDF.Vault.Currency.Entities.FileIteration(connection, file1(0))
    If oFileIteration Is Nothing Then
    MsgBox(“Error: Can’t find the file”)
    Exit Sub
    End If
    Dim oSettings As VDF.Vault.Settings.AcquireFilesSettings =
    New VDF.Vault.Settings.AcquireFilesSettings(connection)
    ‘Going to Checkout and download
    oSettings.DefaultAcquisitionOption = VDF.Vault.Settings.AcquireFilesSettings.AcquisitionOption.Download
    oSettings.OptionsRelationshipGathering.FileRelationshipSettings.IncludeChildren = True
    oSettings.OptionsRelationshipGathering.FileRelationshipSettings.RecurseChildren = True
    oSettings.OptionsRelationshipGathering.FileRelationshipSettings.VersionGatheringOption = _
    VDF.Vault.Currency.VersionGatheringOption.Latest
    oSettings.LocalPath = New VDF.Currency.FolderPathAbsolute(“D:\Vault\Designs\temp-v”) ‘connection.WorkingFoldersManager.GetWorkingFolder(oFileIteration)
    oSettings.AddEntityToAcquire(oFileIteration)
    oSettings.LocalPath = New VDF.Currency.FolderPathAbsolute(“D:\Vault\Designs\temp-v”) ‘connection.WorkingFoldersManager.GetWorkingFolder(oFileIteration)
    connection.FileManager.AcquireFiles(oSettings)
    End If

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading