Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
Richard.MM
in reply to: Jef_E

Here is the code that download drawing from the vault and open it.
But you'll have to modify it for his own use.

VB.net:

 

Imports Autodesk.DataManagement.Client.Framework.Vault
Imports Autodesk.Connectivity.WebServicesTools
Imports VDF = Autodesk.DataManagement.Client.Framework
Imports ACW = Autodesk.Connectivity.WebServices
Imports System.Collections
Imports System.Windows.Forms

Public Class Otevr_zVault
    Dim fileIters As System.Collections.Generic.ICollection(Of VDF.Vault.Currency.Entities.FileIteration)

    Public Shared kontrola As String

    Public Sub stahni_vykr()


        Dim results1 As VDF.Vault.Results.LogInResult = VDF.Vault.Library.ConnectionManager.LogIn("xxx", "xxxx", "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 m_inventorApp As Inventor.Application = Nothing

        ' get running Inventor
        Try
            m_inventorApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")
        Catch ex As Exception
            MsgBox("Error2")
        End Try

        Try
            If m_inventorApp Is Nothing Then
                MsgBox("Error3")
                Return

            End If
        Catch
        End Try

        m_inventorApp.Visible = True

        Dim oDoc As Inventor.Document

        oDoc = m_inventorApp.ActiveDocument

        Dim fullfilename1 As String = oDoc.FullFileName
        Dim vykr As String
        If Not fullfilename1 = Nothing Then


            If oDoc.DisplayName.EndsWith(".ipt") Or oDoc.DisplayName.EndsWith(".iam") Then

                vykr = Microsoft.VisualBasic.Left(oDoc.DisplayName, InStrRev(oDoc.DisplayName, ".")) & "idw"

            ElseIf oDoc.DisplayName.EndsWith(".idw") Then

                vykr = oDoc.DisplayName

            Else

                vykr = oDoc.DisplayName & ".idw"

            End If
        Else
            MessageBox.Show("Error4")
            Return
        End If
        Dim oFolder3 As String = Microsoft.VisualBasic.Left(fullfilename1, InStrRev(fullfilename1, "\") - 1)
        Dim oFolder2 As String = Microsoft.VisualBasic.Left(oFolder3, InStrRev(oFolder3, "\"))
        If fullfilename1 = Nothing Then
            MsgBox("Error5")
            Return
        End If

        Dim fullfilename As String = oFolder2 & "Drawings\" & vykr

        Try
            Dim oFileIteration As VDF.Vault.Currency.Entities.FileIteration = Nothing

            Try

                'convert local path string to vault format
                Dim VaultPath As String = fullfilename
                If VaultPath.Contains("D:\Vault_Working\") Then
                    VaultPath = VaultPath.Replace("D:\Vault_Working\", "$/")
                ElseIf VaultPath.Contains("E:\Vault_Working\") Then

                    VaultPath = VaultPath.Replace("E:\Vault_Working\", "$/")

                Else
                    MsgBox("Error6 " + VaultPath)
                    Return
                End If

                VaultPath = VaultPath.Replace("\", "/")


                Dim VaultPaths() As String = New String() {VaultPath}

                Dim DocService As ACW.DocumentService

                DocService = connection.WebServiceManager.DocumentService
                Dim files As ACW.File() = Nothing
                Try

                    files = DocService.FindLatestFilesByPaths(VaultPaths)

                Catch

                End Try

                Dim file As ACW.File
                file = files(0)

                oFileIteration = New VDF.Vault.Currency.Entities.FileIteration(connection, file)
            Catch ex As Exception

                MsgBox("Error7")
            End Try

            If oFileIteration IsNot Nothing Then


                'get settings
                Dim oSettings As VDF.Vault.Settings.AcquireFilesSettings = New VDF.Vault.Settings.AcquireFilesSettings(connection)

                oSettings.DefaultAcquisitionOption = VDF.Vault.Settings.AcquireFilesSettings.AcquisitionOption.Download 'Or VDF.Vault.Settings.AcquireFilesSettings.AcquisitionOption.Checkout

                oSettings.AddEntityToAcquire(oFileIteration)

                kontrola = "NE"

                connection.FileManager.AcquireFiles(oSettings)

            End If

        Catch ex As Exception

            Dim Rodice As New Rodice
            Call Rodice.GetWhereUsed()
            Return
        Finally

            VDF.Vault.Library.ConnectionManager.LogOut(connection)

        End Try

        m_inventorApp.Documents.Open(fullfilename)
        kontrola = Nothing
    End Sub
End Class