Batch command syntax for calling Python plugins/scripts on Windows XP
This discussion is connected to the gimp-developer-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.
This is a read-only list on gimpusers.com so this discussion thread is read-only, too.
Batch command syntax for calling Python plugins/scripts on Windows XP | Sebastian Koblinger | 11 Oct 13:38 |
Batch command syntax for calling Python plugins/scripts on Windows XP | Sven Neumann | 11 Oct 20:05 |
Batch command syntax for callingPythonplugins/scripts on Windows XP | Sebastian Koblinger | 12 Oct 08:44 |
Batch command syntax for calling Python plugins/scripts on Windows XP
Hi,
I'm working on Win XP - not a very gimpesque enviroment, I know - and I'm troubling with the command line syntax. I'm new to Python and Plugin-writing, so I may do not use the correct terms when I describe my problem;
Basically I want my python commands to be run with the GIMP-Python-console from the WIN XP command line. (Later to make a .bat file of it and run it regularily). I haven't found a way do run python-scripts with the GIMP-Python-console, so my idea is to make a plugin and call the function via the command line.
So first of all I put my python commands into a function (my_function.py) and dropped the file into the plug-ins directory. There are not input parameters in my function so far.
Further I open the command line, go to the directory that contains my pictures to be processed and type:
gimp-2.6 -i --batch-interpreter=python-fu-eval -b python-fu-my-function
which starts to print the usual loading commands but stops with:
Starting extension: 'extension-script-fu' batch command experienced an execution error
Is there essentially anything wrong with my syntax? I even can't run other python-plugins.
I guess the issues are the input paramters of the function. A function requires an image and a drawable as input, am I right? Therefore I see other python-plugins to come with a seperate batch file? As far as I have found out, the batchfile.py makes a list of files to be processed and passes it to the function. To execute the batch file, it is called from the command line. This made me think, if one could directly run the python script with the GIMP-Python console like this:
gimp-2.6 -i --batch-interpreter=python-fu-eval -b my_script.py
My setup: GIMP 2.6.10, Python 2.6.5. Any hints will be appreciated.
-Sebastian
Batch command syntax for calling Python plugins/scripts on Windows XP
On Mon, 2010-10-11 at 15:38 +0200, Sebastian Koblinger wrote:
Further I open the command line, go to the directory that contains my pictures to be processed and type:
gimp-2.6 -i --batch-interpreter=python-fu-eval -b python-fu-my-function
which starts to print the usual loading commands but stops with:
Starting extension: 'extension-script-fu' batch command experienced an execution error
Is there essentially anything wrong with my syntax?
Please post a simple example script to illustrate what you are trying to achieve.
I guess the issues are the input paramters of the function. A function requires an image and a drawable as input, am I right?
No, procedures don't require any input parameters at all. For procedures to be run from the image menu, it makes sense to have an image and a drawable parameters, but even there this is not a requirement.
Sven
Batch command syntax for callingPythonplugins/scripts on Windows XP
Further I open the command line, go to the directory that contains my pictures to be processed and type:
gimp-2.6 -i --batch-interpreter=python-fu-eval -b python-fu-my-function
which starts to print the usual loading commands but stops with:
Starting extension: 'extension-script-fu' batch command experienced an execution error
Is there essentially anything wrong with my syntax?
Please post a simple example script to illustrate what you are trying to achieve.
Of course I forgot the important part, so there you go.
My script/plugin is to be used predominantly from the command line in batch mode.
What it does:
1) Make a list of jpg-files
2) load each jpg and apply a predefined path (provided by an SVG-file) onto it
3) off this path a selection is made and gets inverted
4) the inverted area is filled black
5) file gets saved
There is room for improvement but basically this is my script, some parts are commented out:
#!/usr/bin/env python
from gimpfu import *
import os
import datetime
def my_function():
path = 'G:\\to\\my\\directory'
#folder_list = os.listdir(path)
#day = datetime.datetime.today().strftime("%Y%m%d") # for testing set specific date for variable 'day' day = '20100826' # temporarily set a specific day for testing datestring = path + '\\' + day
# List of files of the current day's directory filelist = os.listdir(datestring)
# filelist should contain just jpg-files. filelist = [ a for a in filelist if '.jpg' in a]
pic = range(len(filelist))
for pic in filelist:
im = pdb.gimp_file_load(datestring + '\\' + pic, pic)
pdb.gimp_vectors_import_from_file(im,
'G:\\to\\my\\directory\\thepath.svg', 1, 0)
pdb.gimp_path_to_selection(im, 'Auswahl', 2, 0, 0, 0, 0)
pdb.gimp_selection_invert(im)
drawable = pdb.gimp_image_get_active_drawable(im)
pdb.gimp_edit_fill(drawable, 0)
pdb.gimp_image_crop(im, 1067, 1055, 296, 105)
# to be set relative to the current image
pdb.file_jpeg_save(im, drawable, datestring + '\\' +
pic[:-4] + '_cut.jpg', pic[:-4] + '_cut.jpg', 1, 0, 0, 0, 'none', 0,
0, 0, 0)
#pdb.gimp_image_delete(gimp.image_list()[0])
pdb.gimp_image_delete(im)
# registration function
register(
"my_function",
"Short description",
"Long description",
"Sebastian Koblinger",
"Sebastian Koblinger",
"October 2010",
"/New Scripts/My special script",
"*",
[],
[],
my_function
)
main()
I guess the issues are the input paramters of the function. A function requires an image and a drawable as input, am I right?
No, procedures don't require any input parameters at all. For procedures to be run from the image menu, it makes sense to have an image and a drawable parameters, but even there this is not a requirement.
Another question that keeps me busy: Are the GIMP modules available only within the GIMP-Python console? So no other console (IDLE in my case) has access to them? That would make things by far easier I guess.
Sebastian