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: 

Vault 2014 File rename using API

10 REPLIES 10
Reply
Message 1 of 11
mnav
1038 Views, 10 Replies

Vault 2014 File rename using API

Hi

 

 Can somebody suggest how we can achive the rename file wizard functionality of Vault 2014 explorer using API.

 i want file to be renamed and file properties like PartNumber get updated automatically.

 

thanks

10 REPLIES 10
Message 2 of 11
Balaji_07
in reply to: mnav

Hi mnav,

 

Add a handler for checkIn event (GetRestriction, Pre or Post based on your requirement)

 

AddHandler DocumentService.CheckinFileEvents.GetRestrictions, AddressOf CheckinFileCheck

 

In that handler event specify the new file name

 

Private Sub CheckinFileCheck(ByVal sender As Object, ByVal e As CheckinFileCommandEventArgs)
       e.NewFileName = "New file name"

End Sub

 

For updating properties if it is going to be vault properties then you have to

  1. Checkout the file
  2. Update the properties using "ServiceManager.DocumentService.UpdateFileProperties(New Long() {oFileIteration.EntityMasterId}, propDefIds.ToArray(), propDefValues.ToArray())" Command
  3. Checkin the file.

 

If you want to update Inventor file properties then you have to

  1. Checkout the file
  2. update the inventor file properties using Inventor Apprentice server or Inventor application
  3. Checkin the file

 

 

Regards,

Balaji A

Message 3 of 11
mnav
in reply to: mnav

Hi BalaJi

 Thanks for your reply.

 we can provide new name on chekin anyway. what is the point of using checkin event.

 For bulk file rename this will not work.

 

thanks

 

Message 4 of 11
Littlerubarb
in reply to: mnav

To manipulate any properties you need to use the Checkout/Checkmethods as described by BalaJi(Just the way it is :)...

 To do a batch rename you would need to do something like so..

 

Dim fileItem As Vault.Currency.Entities.FileIteration = Nothing

Dim oSettings As Vault.Settings.AcquireFilesSettings = New Vault.Settings.AcquireFilesSettings(m_conn)
            'Going to Checkout and download
            oSettings.DefaultAcquisitionOption = Vault.Settings.AcquireFilesSettings.AcquisitionOption.Checkout Or Vault.Settings.AcquireFilesSettings.AcquisitionOption.Download
            oSettings.AddEntityToAcquire(fileItem)
            'set the path to the working folder
            oSettings.LocalPath = m_conn.WorkingFoldersManager.GetWorkingFolder(fileItem) 'fldrPath
            'Do the download
            m_conn.FileManager.AcquireFiles(oSettings)

             'Checkin the File
            m_conn.FileManager.CheckinFile(fileItem, "Modified", False, New ACW.FileAssocParam() {}, Nothing, False, {Your New FileNAme as String}, ACW.FileClassification.None, False, filePathAbs)
          

 

 

 

 

 

 

 

 

Message 5 of 11

This doesn't seem to be working.

The checkinFile function work until I enter a parameter for checkin name. When I do that it will generate an exception (exception 0) with no extra detail about the error.

This code generate error: mainconnection.FileManager.CheckinFile(oFileIteration, Nothing, False, New Autodesk.Connectivity.WebServices.FileAssocParam() {}, Nothing, False, "NewFileName.IPT", Autodesk.Connectivity.WebServices.FileClassification.None, False, Nothing)

 

But this one works:

mainconnection.FileManager.CheckinFile(oFileIteration, Nothing, False, New Autodesk.Connectivity.WebServices.FileAssocParam() {}, Nothing, False, nothing, Autodesk.Connectivity.WebServices.FileClassification.None, False, Nothing)

Message 6 of 11

Ok so the previous code is mising one line.. after the download make you changes like below.

 

'Do the download
            m_conn.FileManager.AcquireFiles(oSettings)
 'Change The properties
            Change_Prop(fileItem, m_conn)
 'Checkin the File
            m_conn.FileManager.CheckinFile(fil...

 

 

This should help you solve your issue

 

http://justonesandzeros.typepad.com/blog/2015/02/another-way-to-update-properties.html

 

Message 7 of 11

            Change_Prop(fileItem, m_conn) seems to be a custom function. I didn't find this function is Vault SDK documentation.

The closed that I found was

 Sub UpdateFileProperties( _
ByVal file As File, _
ByVal props As System.Collections.Generic.Dictionary(Of PropDef,Object) _
)

 

As the second parameter, we have to specify what properties shoudl get updated.

Can you be more precise about the funvtion or if you have developed the change_prop, you can post it please.

 

Thanks

 

Message 8 of 11

Change_Prop(file As Vault.Currency.Entities.FileIteration, m_conn As Vault.Currency.Connections.Connection) - is a custom action, the idea is that you follow the steps as previously defined and then create your custom change.

 

what every your script is it needs to run something like this to make the change

 

 

Dim propDef As Vault.Currency.Properties.PropertyDefinition

Dim oldprop As String

returnvalue = oldprop.Value.ToString()

 

'Change the Property
                                m_conn.WebServiceManager.DocumentService.UpdateFileProperties(New Long() {file.EntityMasterId}, New Long() {propDef.Id}, New String() {returnvalue})

 

Let me know if this works


                           

Message 9 of 11

What I need to do, as the tile of this page suggests, is renaming vault files. And I don't know what properties I should modify to to rename the file in vault.

Do you have any real code that rename files in the vault?

 

 

Message 10 of 11

This exmaple should have everything you need..

 

http://adndevblog.typepad.com/manufacturing/2013/11/vault-2014-api-example-getting-property-values-o...

 

I haven't tested this, but it should be something like this...


I use the Public Function getFileIteration _ from the previous link

Dim fileItem As Vault.Currency.Entities.FileIteration = Nothing
fileItem = getFileIteration("Name of Your File", m_conn)
Dim fldrPath As Framework.Currency.FolderPathAbsolute = m_conn.WorkingFoldersManager.GetWorkingFolder(fileItem)
Dim filePath As String = Path.Combine(fldrPath.ToString(), fileItem.EntityName)
Dim filePathAbs As Framework.Currency.FilePathAbsolute = New Framework.Currency.FilePathAbsolute(filePath)


' Checkin substituting NewFileName As String
m_conn.FileManager.CheckinFile(fileItem, "Modified", False, New ACW.FileAssocParam() {}, Nothing, False, newFileName As String, ACW.FileClassification.None, False, filePathAbs)
      

Message 11 of 11

Ok.

I think I figured out what I was missing!

I had the comment argument as null. Apparently, if we are checking in the file with a new name, there should be a comment for it. For regular checking in, comment is no necessary, but for renaming having a comment is mandatory.

 

 

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

Post to forums  

Autodesk Design & Make Report