This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

VBScript Set PDF file name in multifile

Hi everyone!

We have a workflow that created multifile with PDF when the object enters a certain state. We would like to set FILENAME of PDF same as a property "Document code". Is there a simple way or do I need to write a script? If so, can anyone help me? I am a beginner at scripting...

thank you!

Dejan

Parents
  • Hi, Dejan,

    I suggest something like code below:

    'Get All ObjectFiles of current object:
    Vault.ObjectFileOperations.GetFilesForModificationInEventHandler ObjVer
    
    Dim ObjectFileCollection: Set ObjectFileCollection = Vault.ObjectFileOperations.GetFiles(ObjVer)
    
    'Iterate all object files.
    For i = 1 To ObjectFileCollection.Count
         
        'Get object file for current iteration  from object file collection 
        Dim CurrentObjectFile: Set CurrentObjectFile = ObjectFileCollection.Item(i)
    	
    	szExt = LCase(CurrentObjectFile.Extension)
    	szTitle = CurrentObjectFile.Title
    
    	If Right (szExt,4) = ".pdf" Then 
    		szNewTitle = "New_" & szTitle
    		Vault.ObjectFileOperations.RenameFile ObjVer, CurrentObjectFile.FileVer, szNewTitle, szExt , False
    	End If 
    Next

  • Hi Ne0Tr0n!

    Thanks for the fast reply.

    Would this rename the whole MFD or just the PDF file? Because it does not work:/.

    shouldnt szNewTitle be something like  szNewTitle = szDocCode ?

    Because i want to set the filename of PDF same as the value of property 1518 which is text based property.

  • Hi,

    This example script rename every PDF file in MFD. If you have more than one file you must use different names for each one.

    I make little mistake in line 17 it should be :

        Vault.ObjectFileOperations.RenameFile ObjVer, CurrentObjectFile.FileVer, szNewTitle, szExt , False

    instead of:

        Vault.ObjectFileOperations.RenameFile ObjVer, CurrentObjectFile.FileVer, szTitle, szExt , False

    Can you provide your source code?

  • Hi,

    here is my Script Code:

    'Get All ObjectFiles of current object:
    Vault.ObjectFileOperations.GetFilesForModificationInEventHandler ObjVer
    
    Dim ObjectFileCollection: Set ObjectFileCollection = Vault.ObjectFileOperations.GetFiles(ObjVer)
    dim szDocCode
    
    szDocCode = PropertyValues.SearchForProperty( 1518 ).TypedValue.GetValueAsUnlocalizedText
    
    
    'Iterate all object files.
    For i = 1 To ObjectFileCollection.Count
         
        'Get object file for current iteration  from object file collection 
        Dim CurrentObjectFile: Set CurrentObjectFile = ObjectFileCollection.Item(i)
    	
    	szExt = LCase(CurrentObjectFile.Extension)
    	szTitle = CurrentObjectFile.Title
    
    	If Right (szExt,4) = ".pdf" Then 
    		szNewTitle = szDocCode
    		 Vault.ObjectFileOperations.RenameFile ObjVer, CurrentObjectFile.FileVer, szNewTitle, szExt , False
    	End If 
    Next

    But it does not set my PDF filename to the value that I want, which is the value I have in property 1518.

Reply
  • Hi,

    here is my Script Code:

    'Get All ObjectFiles of current object:
    Vault.ObjectFileOperations.GetFilesForModificationInEventHandler ObjVer
    
    Dim ObjectFileCollection: Set ObjectFileCollection = Vault.ObjectFileOperations.GetFiles(ObjVer)
    dim szDocCode
    
    szDocCode = PropertyValues.SearchForProperty( 1518 ).TypedValue.GetValueAsUnlocalizedText
    
    
    'Iterate all object files.
    For i = 1 To ObjectFileCollection.Count
         
        'Get object file for current iteration  from object file collection 
        Dim CurrentObjectFile: Set CurrentObjectFile = ObjectFileCollection.Item(i)
    	
    	szExt = LCase(CurrentObjectFile.Extension)
    	szTitle = CurrentObjectFile.Title
    
    	If Right (szExt,4) = ".pdf" Then 
    		szNewTitle = szDocCode
    		 Vault.ObjectFileOperations.RenameFile ObjVer, CurrentObjectFile.FileVer, szNewTitle, szExt , False
    	End If 
    Next

    But it does not set my PDF filename to the value that I want, which is the value I have in property 1518.

Children
  • You are absolutely right. In line  19 "If" statement is overkill.

    If Right (szExt,4) = ".pdf" Then

    Try simple:

    If szExt = "pdf" Then

    I add and current file number in case you have more than one pdf. Here is full code:

    'Get Property ID by Alias
    Dim iDocCode: iDocCode = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("PD.DocCode")
    
    'Get All ObjectFiles of current object:
    Vault.ObjectFileOperations.GetFilesForModificationInEventHandler ObjVer
    
    Dim ObjectFileCollection: Set ObjectFileCollection = Vault.ObjectFileOperations.GetFiles(ObjVer)
    dim szDocCode
    
    szDocCode = PropertyValues.SearchForProperty( iDocCode ).TypedValue.GetValueAsUnlocalizedText
    
    
    'Iterate all object files.
    For i = 1 To ObjectFileCollection.Count
         
        'Get object file for current iteration  from object file collection 
        Dim CurrentObjectFile: Set CurrentObjectFile = ObjectFileCollection.Item(i)
    	
    	szExt = LCase(CurrentObjectFile.Extension)
    	szTitle = CurrentObjectFile.Title
    
    	If szExt = "pdf" Then 
    		szNewTitle = szDocCode & "_" & i
    		 Vault.ObjectFileOperations.RenameFile ObjVer, CurrentObjectFile.FileVer, szNewTitle, szExt , False
    	End If 
    Next

  • Thank you very much Ne0Tr0n!

    It works!:) I just had to change iDocCode to my value and it works perfectly!