Disclaimer
I have not thoroughly analysed everything Python-related in DOpus scripting - far from that. If you have some other problems/questions - ask, I will try to answer.
Intoduction
DOpus scripting capabilities are based on Microsoft COM and ActiveScripting technologies. DOpus support for them is geared towards languages that are "native" to ActiveScripting and bundled with Windows, ie. JScript and VBScript, much like some shell extensions are geared specifically towards Windows Explorer (making problems with DOpus). That is why the support causes some problems with "non-native" Python.
Components
I use python.org python and pywin32 on Windows 7 (all 64-bit versions) with 64-bit DOpus (free ActivePython is very weakly supported). No special setup is necessary.
Remember to always use .pys (PythonScript) file extension for DOPus Python scripts, otherwise scripting engine doesn't detect them.
Misc
When developing, keep PythonWin, Tools> Trace Collector debugging tool window open, to see extended problem information.
Also, 'import win32traceutil' in your script, to have more debug info displayed in the above window.
Issue 1 - Calling functions
Some functions exposed by DOpus cannot be properly called, or a call produces invalid result. My impression is that this is the case for functions supporting 0 or more arguments and functions in DOpus native datatype objects, like Vector.
You can observe this problem in two ways:
- A script just silently dies on a line with function call. (In fact, it fails with com_error exception which is not propagated from Python; you can see it in Trace Collector debugging tool window.)
- You get an unexpected exception in DOpus debug console (eg. AttributeError: .Blob) on a seemingly innocuous function call.
Solution:
Mark an object attribute as function before calling it:
object._FlagAsMethod('function')
result = object.function()
or in real life:
DOpus._FlagAsMethod('Create')
factory = DOpus.Create()
factory._FlagAsMethod('Vector')
myvec=factory.Vector()
instead of just
myvec=DOpus.Create().Vector()
Note, you need to flag each function just once per object lifetime. Flagging is a low cost (like putting value in a simple dictionary) and idempotent operation (you can execute it multiple times for a function with no side-effects).
Issue 2 - Indexing collections
Indexing collections with [] may not always work. You get TypeError: This object does not support enumeration in DOpus debug window. Just use () instead of []. This is actually normal when using pywin, and not specific to DOpus. So, you need to use:
for l in DOpus.listers:
DOpus.Output(DOpus.listers(l).title)
Issue 3 - Default values
Some objects (eg. Toolbar) are described in documentation as having . To get this value, simply interpret the object using datatype of the value, eg.:
for t in DOpus.toolbars:
DOpus.Output(DOpus.toolbars(t))
This gets toolbars' names: of a Toolbar object is a string.
Sample script
Below you can find a simple columns script, that uses MediaInfo library to fetch metadata from video files. MediaInfo is imo much faster than DOpus functions, and supports more video formats. But don't mix DOpus and MediaInfo video columns in one file panel, because it will make data display much slower!
This is not a polished piece of software (like I don't check whether MediaInfo.dll has actually loaded)- just something concrete to get started and play with.
Note, you will get English captions if your DOpus language is other than Polski.
Script setup:
Download MediaInfo DLL from mediaarea.net/en/MediaInfo/Download/Windows - get DLL without installer. Put \MediaInfo.dll into %WINDIR%\system32, put \Developers\Source\MediaInfoDLL\MediaInfoDLL3.py into \Lib\site-packages\ (assumes Python 3)
Put the script as .pys file (removing .txt extension) in /dopusdata/Script AddIns
\Developers\List_Of_Parameters*.csv files contain information about possible values to play with.
And the script:
MediaInfo media columns.pys.txt (7.22 KB)
Have fun!