Community
Vault Customization
Share your knowledge, ask questions, and explore popular Vault API, Data Standard, and VBA topics related to programming, creating add-ins, or working with the Vault API.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Renaming Files in Vault: Is there anything I need to be mindful of?

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
dsouva
528 Views, 5 Replies

Renaming Files in Vault: Is there anything I need to be mindful of?

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

 

 

5 REPLIES 5
Message 2 of 6
Nick_Hall
in reply to: dsouva

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

Message 3 of 6
dsouva
in reply to: Nick_Hall

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

 

Message 4 of 6
Nick_Hall
in reply to: dsouva

Hi

 

The links that Markus Koechl has posted here should help

 

https://forums.autodesk.com/t5/vault-customization/checking-in-file-through-vault-2023-api-makes-fil...

 

The sample code is in C#, but it's fairly easy to convert to VB

 

Message 5 of 6
Maxim-CADman77
in reply to: dsouva

@dsouva 
I wonder what is 'GlobalVariables' for this code?

Message 6 of 6
Maxim-CADman77
in reply to: dsouva

@dsouva why this ID is hard-coded?

Dim oFileMasterID As Long = 202934

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report