I'm going to be doing a mass name change to .ipt's in our Vault to bring filenames up to our new naming convention. I'm very inexperienced in languages other than VBA (still getting used to VB.NET) and even less experienced in Vault API. Is there anything I should be mindful of when writing this code? ie. Anything that can break Parent/Child relationships? Do I need to update file references prior to renaming?
I tested this in our sandbox Vault and it seems like it's working as expected but it just seems too easy. Like I'm missing something...
Public Sub CommandExecute(ByVal sender As Object, ByVal e As Autodesk.Connectivity.Explorer.Extensibility.CommandItemEventArgs)
Dim rFolder As VDF.Vault.Currency.Entities.Folder = GlobalVariables.connection.FolderManager.RootFolder
Dim oFolderRelative As String = "\Designs\USA-10\Production Parts\T_\TL\TL0_"
Dim strLPath As String = GlobalVariables.connection.WorkingFoldersManager.GetWorkingFolder(Strings.Replace(rFolder.FullName & oFolderRelative, "\", "/")).FullPath
Dim MyString(0) As String
MyString(0) = Strings.Replace(rFolder.FullName & oFolderRelative & "/", "\", "/") ' & sOldFileName
Dim oFileMasterID As Long = 202934
' need to use file master ID below
Dim oFile = GlobalVariables.connection.WebServiceManager.DocumentService.GetLatestFileByMasterId(oFileMasterID) 'FindLatestFilesByPaths(MyString)
Dim oFiles() = GlobalVariables.connection.WebServiceManager.DocumentService.GetFilesByMasterId(oFileMasterID)
Dim sNewFileName As String = "TL0100M5 - MTL #LBA FAN DCK LDR STDOFF.ipt"
Dim sOldFileName As String = oFile.Name
Try
'test connection
If GlobalVariables.connection Is Nothing Then
MsgBox("Unable to establish a connection to Vault.", "Connection Failed")
Exit Sub
End If
' check if local folder exists and create it if it doesn't
If Not System.IO.Directory.Exists(strLPath) Then
System.IO.Directory.CreateDirectory(strLPath)
End If
'check out settings
Dim coSettings As AcquireFilesSettings = New VDF.Vault.Settings.AcquireFilesSettings(GlobalVariables.connection)
coSettings.OptionsRelationshipGathering.FileRelationshipSettings.VersionGatheringOption = Autodesk.DataManagement.Client.Framework.Vault.Currency.VersionGatheringOption.Latest
coSettings.OptionsResolution.OverwriteOption = AcquireFilesSettings.AcquireFileResolutionOptions.OverwriteOptions.ForceOverwriteAll
coSettings.LocalPath = New VDF.Currency.FolderPathAbsolute(strLPath)
coSettings.AddFileToAcquire(New VDF.Vault.Currency.Entities.FileIteration(GlobalVariables.connection, oFile),
VDF.Vault.Settings.AcquireFilesSettings.AcquisitionOption.Download Or
VDF.Vault.Settings.AcquireFilesSettings.AcquisitionOption.Checkout)
Dim MyResults As VDF.Vault.Results.AcquireFilesResults = GlobalVariables.connection.FileManager.AcquireFiles(coSettings)
Dim r As Autodesk.DataManagement.Client.Framework.Vault.Results.FileAcquisitionResult
If MyResults IsNot Nothing Then
For Each r In MyResults.FileResults
Dim ff As VDF.Vault.Currency.Entities.FileIteration = GlobalVariables.connection.FileManager.
CheckinFile(New VDF.Vault.Currency.Entities.FileIteration(GlobalVariables.connection, oFile), "Filename was " _
& sOldFileName, False, Nothing, Nothing, True, sNewFileName, oFile.FileClass, False, New VDF.Currency.
FilePathAbsolute(strLPath & "\" & sOldFileName))
Next
End If
Catch ex As Exception
' Display error message
MsgBox("Error renaming file: " & ex.Message & "" & ex.Source)
End Try
End Sub
Solved! Go to Solution.
Solved by Nick_Hall. Go to Solution.
Hi
The only thing I can see that might caused you problems is that you are passing "Nothing" as the "associations" parameter
This shouldn't be an issue if you are renaming a file that has no children, such as an Inventor part or an AutoCAD drawing without Xrefs, but may cause problems for things like assemblies
It's easy to check - just go to the "Uses" tab
Nick
Great point. I just tried it on a derived part and it didn't maintain the relationship... Do you have any good references for getting the file association? I create a variable (below) but I can't set it to "oFile.FileAssociations". Should it be a different type?
Dim sFileAssoc As FileAssocParam
Hi
The links that Markus Koechl has posted here should help
The sample code is in C#, but it's fairly easy to convert to VB
Can't find what you're looking for? Ask the community or share your knowledge.