Query if parts has already been retrieved in Vault

Query if parts has already been retrieved in Vault

beyEZWUB
Participant Participant
365 Views
3 Replies
Message 1 of 4

Query if parts has already been retrieved in Vault

beyEZWUB
Participant
Participant

Hi dear community,

 

And again a problem:D
The goal is to reverse the code below so that it compares the local folder with the one in the Vault and sees if and which files have not yet been retrieved from the Vault.

The code now works the other way around.

I hope you can help me

Thanks a lot

 

 

Imports System
Imports System.IO
Imports System.Text
Imports ACW = Autodesk.Connectivity.WebServices
Imports VDF = Autodesk.DataManagement.Client.Framework 
Imports VB = Connectivity.Application.VaultBase
AddReference "Autodesk.Connectivity.WebServices.dll"
AddReference "Autodesk.DataManagement.Client.Framework.Vault.dll"
AddReference "Connectivity.Application.VaultBase.dll"

 

Class LocalWorkspaceCheck
Shared FileTypes As New List(Of String) From {".ipt", ".iam", ".dwg", ".ipn", ".xlsx"}
Shared LocalWorkspace As String = "C:\your local vault"

Sub Main
Dim starttime As DateTime = Now
	Dim mVltCon As VDF.Vault.Currency.Connections.Connection 
	mVltCon = VB.ConnectionManager.Instance.Connection
	
	If  mVltCon Is Nothing Then
		MessageBox.Show("You MUST be logged in to Vault to perform this action.", "Not Logged", MessageBoxButtons.OK , MessageBoxIcon.Information)
		Exit Sub
	End If
	
	PresentNonVaultFiles()
MsgBox("timer 1 " & Now.Subtract(starttime).TotalSeconds.ToString("0.00"))
End Sub


Sub PresentNonVaultFiles()
	Dim SearchLocation As String = LocalWorkspace
	Dim filelist As New List(Of String)
	Call GetListOfNonVaultFiles(SearchLocation, filelist)
	
	If filelist.Count > 0 Then
		i = MessageBox.Show(filelist.Count & " file(s) found. These are files that may NOT exist in Vault. Please check one by one to make sure they don't exist in Vault."  & vbLf & vbLf & _ 
		" Would you like to see the files?", _
	  	"Non-Vault Files",MessageBoxButtons.YesNo,MessageBoxIcon.Question)

		If i = vbNo Then
	 		Return
		End If
	Else
		MessageBox.Show("No files found", "Non-Vault Files", MessageBoxButtons.OK , MessageBoxIcon.Information)
	 	Return
	End If

		Dim fileListAsString As String = String.Join(System.Environment.NewLine, filelist.ToArray())
		Dim textFile As String = LocalWorkspace & "NonVaultFiles.txt"
	 	My.Computer.FileSystem.WriteAllText(textFile, fileListAsString, False)
		System.Diagnostics.Process.Start(textFile)
		
		MessageBox.Show("The file was created in the following directory: " & LocalWorkspace & "NonVaultFiles.txt", "File Created", MessageBoxButtons.OK , MessageBoxIcon.Information)
End Sub

Sub GetListOfNonVaultFiles(ByVal SearchLocation As String, ByRef filelist As List(Of String))
	For Each file As String In Directory.GetFiles(SearchLocation)
		Dim attributes = IO.File.GetAttributes(File)

		If (FileTypes.Contains(IO.Path.GetExtension(File))) Then
			If ((attributes And FileAttributes.ReadOnly) <> FileAttributes.ReadOnly) Then
				If (Search_Vault_by_FilePath(File, LocalWorkspace) Is Nothing) Then filelist.Add(File)
			End If
		End If
	Next

	For Each dir As String In Directory.GetDirectories(SearchLocation)
		If (Right(Dir,2) <> "_V") And Not Dir.Contains("OldVersions") Then
				GetListOfNonVaultFiles(Dir, filelist)
		End If
	Next
End Sub

    Function Search_Vault_by_FilePath(filePath As String, LocalWorkspace As String) As ACW.File()
        Dim mVltCon As VDF.Vault.Currency.Connections.Connection = VB.ConnectionManager.Instance.Connection
        If mVltCon Is Nothing Then Return Nothing

        Dim VaultPath As String = filePath.Replace(LocalWorkspace, "$/").Replace("\", "/")
MessageBox.Show("Vault",VaultPath)
        Dim Results As ACW.File() = mVltCon.WebServiceManager.DocumentService.FindLatestFilesByPaths(New String() {VaultPath})

        If (Results(0).Id = -1) Then Return Nothing

        Return Results
    End Function
End Class

 

0 Likes
366 Views
3 Replies
Replies (3)
Message 2 of 4

jjstr8
Collaborator
Collaborator

I don't know how much detail you're looking for, but the basic steps are:

  1. Convert the working folder path to a Vault folder path
  2. Get the Vault "Folder" object (<connection>.WebServicesManager.DocumentService.GetFolderByPath)
  3. Get the files in that folder (<connection>.WebServicesManager.DocumentService.GetLatestFilesByFolderId)
  4. Loop through the results of step 3
    1. Create a FileIteration object for each File
    2. Get the full path to the local file (<connection>.WorkingFoldersManager.GetPathOfFileInWorkingFolder(<file iteration>).FullPath
    3. Check if the file exists
0 Likes
Message 3 of 4

beyEZWUB
Participant
Participant

Hi, sorry for the late answer.

the approach sounds good, now i still have the problem that when referring the .dll in the vba editor for the vault always the error code 48 appears.

with Addreference "*.dll" and import "*.dll" it does not work. The SDK was also installed.
I have read a few times that vba does not work with newer libraries? I do not know if there is something to it.

 

 

0 Likes
Message 4 of 4

jjstr8
Collaborator
Collaborator

You're better off doing this in iLogic or an add-in, not VBA, if it even could be done in VBA.

0 Likes