I've been wrestling with this one for some days now
. I've looked at other postings and they don't seem to offer an example of what I am trying to achieve:
I have a Windows 10 batch file ExportTaggedLayersToPNG.bat that contains:
"C:\Program Files\GIMP 2\bin\gimp-console-2.8.exe" --no-data --no-fonts --no-interface "%~1" -b "(python-fu-export-layers-as-png)" -b "(gimp-quit 0)"
python-fu-export-layers-as-png is the routine written by @paynekj and modified slightly to meet my needs. paynekj's routine works exactly as expected if I start Gimp, load an image and call the function from the menu entry that the plug-in registers. However, I want to call it from the command line in a batch file. As a first approximation, I called the Gimp console EXE with the command line above. The response I get is:
C:\PROJECTS\Images>"C:\Program Files\GIMP 2\bin\gimp-console-2.8.exe" --no-data --no-fonts --no-interface "Test.xcf" -b "(python-fu-export-layers-as-png)" -b "(gimp-quit 0)"
(gimp-console-2.8.exe:6888): LibGimpBase-WARNING **: gimp-console-2.8.exe: gimp_wire_read(): error
GIMP-Error: Unable to run plug-in "pcre3.dll"
(C:\Program Files\GIMP 2\lib\gimp\2.0\plug-ins\pcre3.dll)
Failed to execute child process (Exec format error)
GIMP-Error: Unable to run plug-in "bimp-uninstall.exe"
(C:\Program Files\GIMP 2\lib\gimp\2.0\plug-ins\bimp-uninstall.exe)
Failed to execute child process (Invalid argument)
GIMP-Error: Unable to run plug-in "bimp-locale"
(C:\Program Files\GIMP 2\lib\gimp\2.0\plug-ins\bimp-locale)
Failed to execute child process (No such file or directory)
GIMP-Error: Unable to run plug-in "Readme.txt"
(C:\Users\Ross\.gimp-2.8\plug-ins\Readme.txt)
Failed to execute child process (Exec format error)
GIMP-Error: Unable to run plug-in "Changelog.txt"
(C:\Users\Ross\.gimp-2.8\plug-ins\Changelog.txt)
Failed to execute child process (Exec format error)
GIMP-Error: Unable to run plug-in "autosave.cfg"
(C:\Users\Ross\.gimp-2.8\plug-ins\autosave.cfg)
Failed to execute child process (Exec format error)
batch command experienced an execution error:
Error: ( : 1) Invalid number of arguments for python-fu-export-layers-as-png (expected 2 but received 0)
which tells me (despite the flood of seemingly unrelated errors) that I can find the plug-in and call it successfully. I never expected the parameters to be correct because paynekj's routine expects parameters (only one from my reading of the code, but it's complaining about not getting the expected
2). So I believe I am real close now...
My questions:
- Why all the error messages when I start Gimp? It looks to me like it is trying to run all of the files in my plug-in folder as executables.
- What are the two parameters the routine is expecting? The declaration of the routine is:
...
# this is the bit that does all the work
def export_layers_as_png(img):
...
which suggests only one parameter might be expected.
- I deliberately introduced some bad syntax source code to see how errors are reported. I got:
batch command experienced an execution error:
Error: ( : 1) eval: unbound variable: python-fu-export-layers-as-png
which I guess points to a failure to compile that routine. Is there any way of getting error location a bit more precise?
- is there some method to the madness that seems to surround function naming? I see spaces, underscores, hyphens, a prepended "
python-fu", but nowhere do I see the function referred to by the name given to it in the source.
I can live with the other quirks, but the main problem I have is the connection between the function call as passed with -b parameter in the batch file, and the function as declared in the .py file.