GP SoftwareTwitter
Opus FAQsManualCommandsObjects

Sample Code: Filter selected files by metadata type

scripting

#1

This sample script shows you how you can filter selected files by their metadata type and handle them to do stuff you need.

You can test it in a button.

I hope it will help someone to start with a similar project.

@disablenosel
@filesonly

@script vbscript
' This sample script show you how you can filter selected files by their metadata type
' and handle them to do stuff you need.

Function OnClick(ByRef ClickData)

    ' ============================================================================
    '                         INITIATE VARIABLES & OBJECT
    ' ============================================================================
    Set cmd = ClickData.Func.command
    Set srce = ClickData.Func.sourcetab

    ' ============================================================================
    '                         FILTER FILES TO BE PROCESSED
    ' ============================================================================
    DOpus.Output ""
    DOpus.Output "============================================================================"
    DOpus.Output ""
    DOpus.Output "Selected files BEFORE filter : " & srce.selected_files.count
    DOpus.Output "Files that will actually be processed BEFORE filter : " & cmd.files.count
    cmd.ClearFiles ' All items are removed from the collection so only image files will be added next
    DOpus.Output ""
    DOpus.Output "FILTERING…"
    DOpus.Output ""
    n = 1
    For Each f In srce.selected_files
        ' If a selected file can handle GPS metadata, it will be added to files to process
        If (f.metadata = "image") then
            cmd.AddFile(f)
            DOpus.Output n & ". """ & f.name & """ will be processed"
        End if
        n = n+1
    Next
    DOpus.Output ""
    ' Select files in the active tab that will actually be processed
    cmd.RunCommand("Select FROMSCRIPT DESELECTNOMATCH MAKEVISIBLE")
    srce.Update ' Synchronize changes made by the previous select command to the sourcetab object. It can be useful if you need to use this object later.
    DOpus.Output "Selected files AFTER filter : " & srce.selected_files.count
    DOpus.Output "Files that will actually be processed AFTER filter : " & cmd.files.count

    ' Check if at least 1 file is selected to continue else warn and exit.
    If cmd.files.count < 1 Then
        Set dlg = ClickData.Func.Dlg
        dlg.Request "No file selected or no valid file to process."  & vbCrLf & "Please select at least 1 image file and run the command again", "OK"
        Set dlg = Nothing ' destroy dialog
        Exit Function
    End If

    ' ============================================================================
    '                             DO YOUR STUFF
    ' ============================================================================
    ' Go on with what you need to do with those files next.
    ' Now any cmd.RunCommand will apply to the files that are actually selected.

End Function

Useful resources


#2

Dear Fred, I want use it but can't. how to use it? I click copy for copy the script code> customize > create a new button & paste the code in function > OK
but when i click the button it's show an error massage. can u please tell me in details how can use ur script.


#3

@khalidhosain: Please link your account. I won't ask again.