I'm having difficulty getting a script of mine to work on the context menu and was hoping somebody could help me solve this. The script basically just passes selected video files to two other programs to verify that they aren't corrupted. The script works fine as a button, but when I add it to a file context menu, it generates this error:
Error at line 28, position 2
Invalid procedure call or argument: 'oDlg.Create' (0x800a0005)
Is the scripting functionality unable to create DOpus.dlg dialogs from context menus? When I created the context menu item, I created it as a "Run an Opus function" type and set the Function field to "Script Function". I pasted in the code exactly as it is on my button. After it initially failed, I even tried adding this to the top of the script (since there isn't a "Script Type" field like the buttons have):
@script vbscript
But that didn't help any. Am I doing something incorrectly here? Any help would be greatly appreciated. Oh, and I'm using Directory Opus Pro v12.22 x64 on Windows 10 Pro v2004 (19041.630). Thanks!
Here's my script code
Option Explicit
'=================================================
' This script checks selected files and runs MediaInfo.exe to see if they're damaged or not.
' If no files are selected, it will check all files in the current folder.
'=================================================
Function OnClick(ByRef ClickData)
ClickData.Func.Command.Deselect = False 'Make sure this script doesn't deselect any selected files.
Dim aFiles(), iCnt, iDamaged, iFiles, iLines, iLines2, iUndamaged, oDlg, oExec, oFile, oFiles, oMsg, oShell, oWarnDlg, sDamagedMsg, sFiles, sLine, sNum, sUndamagedMsg
Const cMediaInfo = "C:\Program Files\MediaInfo_CLI\MediaInfo.exe" 'MediaInfo.exe location.
Const cFFProbe = "C:\Program Files\ffmpeg\bin\ffprobe.exe" 'FFProbe.exe location.
Set oShell = CreateObject("WScript.Shell") 'Create a scripting shell object.
'Create dialogs.
Set oWarnDlg = DOpus.Dlg
oWarnDlg.window = ClickData.Func.SourceTab
oWarnDlg.top = True
oWarnDlg.title = "Is Video Damaged?"
oWarnDlg.buttons = "OK"
Set oDlg = DOpus.Dlg
oDlg.window = ClickData.Func.SourceTab
oDlg.top = True
oDlg.template = "dialog"
oDlg.detach = True
oDlg.buttons = "OK"
oDlg.Create
'If no files were selected, then use all files in the lister.
If ClickData.Func.SourceTab.SelStats.SelFiles = 0 Then
Set oFiles = ClickData.Func.SourceTab.Files
Else
Set oFiles = ClickData.Func.SourceTab.Selected_Files
End If
'Get the list of files.
sFiles = ""
iFiles = 0
For Each oFile In oFiles
ReDim Preserve aFiles(2, iFiles)
aFiles(0, iFiles) = oFile.name
aFiles(1, iFiles) = False
aFiles(2, iFiles) = oFile.realpath
sFiles = sFiles & " """ & oFile.realpath & """"
iFiles = iFiles + 1
next 'oFile
'Run the MediaInfo program if files were selected.
If iFiles > 0 Then
'Run MediaInfo and read the output.
iLines = 0
Set oExec = oShell.Exec(cMediaInfo & " --Output=General;%IsTruncated%\n" & sFiles)
Do
sLine = oExec.StdOut.ReadLine()
If Not oExec.StdOut.atEndOfStream Then
If UCase(sLine) = "YES" Then
aFiles(1, iLines) = True
End If
iLines = iLines + 1
End If
Loop While Not oExec.StdOut.atEndOfStream
'Run FFProbe and read the output.
For iCnt = 0 To iFiles - 1
sLine = ""
Set oExec = oShell.Exec("""" & cFFProbe & """ -v error """ & aFiles(2, iCnt) & """")
Do
sLine = sLine & oExec.StdErr.ReadLine()
Loop While Not oExec.StdErr.atEndOfStream
If sLine <> "" Then
aFiles(1, iCnt) = True
End If
Next
' Make sure the number of responses from MediaInfo matches the number of files selected.
If iLines = iFiles Then
' Check the results for each file.
iDamaged = 0
iUndamaged = 0
sDamagedMsg = ""
sUndamagedMsg = ""
sNum = ""
For iCnt = 0 To iFiles - 1
If iFiles > 9 Then
If iCnt > 8 Then
sNum = ""
Else
sNum = "0"
End If
End If
If aFiles(1, iCnt) = True Then
iDamaged = iDamaged + 1
oDlg.Control("damaged").AddItem(sNum & iDamaged & ") " & aFiles(0, iCnt))
Else
iUndamaged = iUndamaged + 1
oDlg.Control("undamaged").AddItem(sNum & iUndamaged & ") " & aFiles(0, iCnt))
End If
Next
' Display the result.
oDlg.Show
Do
oMsg = oDlg.GetMsg()
Loop While oMsg
Else
oWarnDlg.message = "ERROR! The program didn't check all files correctly."
oWarnDlg.Show
End If
Else
oWarnDlg.message = "No files selected."
oWarnDlg.Show
End If
oShell.AppActivate(ClickData.Func.SourceTab.Path) 'Bring Directory Opus back to the front.
'Release object's memory.
Set oDlg = Nothing
Set oExec = Nothing
Set oFile = Nothing
Set oFiles = Nothing
Set oMsg = Nothing
Set oShell= Nothing
Set oWarnDlg = Nothing
End Function 'OnClick