2

I am trying to execute a Python piece of code in batch mode to edit an existing Gimp file. Getting the following error

batch command experienced an execution error: Error: ( : 1) eval: unbound variable: commmand-line-execution

Here is the code I am using:


#!/usr/bin/env python

from gimpfu import *

# the script
def my_tf_cmd_function(fle, fontname, fontsize) :
    image = pdb.gimp_file_load(fle,fle)
    drawable = pdb.gimp_image_get_active_layer(image)
    image.undo_group_start()
    foreground = gimp.get_foreground()  
    gimp.set_foreground(240,240,240)
    textlayer1 = gimp.Layer(image, "Troo", drawable.width, drawable.height, RGBA_IMAGE, 100, NORMAL_MODE)
    image.add_layer(textlayer1, 0)
    pdb.gimp_drawable_fill(textlayer1, 3) # transparent fill
    gimp.set_background(255, 255, 255) 
    gimp.set_foreground(240,240,240)
    floattext = pdb.gimp_text_fontname(image, textlayer1, 200, 100, "T", 1, 1, fontsize, 1, fontname)

    pdb.gimp_floating_sel_anchor(floattext)
    gimp.set_foreground(foreground) 
    image.undo_group_end()
    pdb.gimp_file_save(image,  drawable,  "/home/Downloads/img.xcf",  "/home/Downloads/img.xcf")
    return


# This is the plugin registration function
register(
    "command_line_execution",    
    "My Command Line Attempt Python-Fu",
    "This script does nothing and is extremely good at it",
    "RC",      
    "RC", 
    "May 2013",
    "<Image>/MyScripts/My Command Python-Fu", 
    "*", 
    [
      (PF_STRING, "fle", "GlobPattern", "*.*"),
      (PF_FONT, "fontname", "Foo font", "Arial"),
      (PF_INT, "fontsize", "Foo font size", 18)
    ], 
    [],
    my_tf_cmd_function,
    )

main()

Please help.

Martin Valgur
  • 5,793
  • 1
  • 33
  • 45
raj_arni
  • 959
  • 2
  • 15
  • 29
  • You're missing a quote before `/home..` – mata May 25 '13 at 21:29
  • jupp, change `/home/Downloads/img.xcf"` into `"/home/Downloads/img.xcf"` Thats the beauty of syntax highlighting – Fredrik Pihl May 25 '13 at 21:34
  • Thank you for the quick reply. The file_save statement has correct quotes, but I still get the error. – raj_arni May 26 '13 at 00:37
  • Does this answer your question? [How to run python scripts using gimpfu from command line?](https://stackoverflow.com/questions/44430081/how-to-run-python-scripts-using-gimpfu-from-command-line) – Martin Valgur Jul 19 '20 at 17:40

1 Answers1

-2

full answer here: solving gimp unbound variable error

So I came across this question when trying to figure out how to run the function in GIMP.

And I found the answer here: IBM developerWorks

So basically you call the function like so:

gimp -i -b '(python-fu-command-line-execution 0 0 0 "*.*" "Arial" 18)' -b '(gimp-quit 0)'

The first 3 zeros is for the 3 default parameters:

  • INTERACTIVE MODE OR NOT
  • img IMAGE
  • draw DRAWABLE

I know your code doesn't really use any of these, but these are required, so... and as for why they must be integers, I have no idea myself. I trial and error and found that INTEGER works for me.

If anyone have a better understanding of what's going on, do enlighten.

Edit:

So I have this problem myself initially... and I found out that the Error: ( : 1) eval: unbound variable: commmand-line-execution error is caused when inserting the batch command through the CLI in Scheme language.

But to check if your function is registered, go to the Procedure Browser (Help > Procedure Browser) and search for your function, (it will something like python-fu-command-line-execution).

If its not there, check out this article on where to place your plugin files to get it registered: wikibooks.

If it is registered, you can try running it in the Console. (Filters > Python Fu > Console), if it runs, you don't have a issue with your code.

But all the same, you should try running the command in the format first, the error is something related to the scheme command given...

ongspxm
  • 87
  • 1
  • 9
  • This has nothing do to with using the `gimpfu` library, unfortunately. – SiHa Jan 17 '17 at 19:41
  • The `Error: ( : 1) eval: unbound variable: command-line-execution` error is when you are trying to call the function from the command line where it uses Scheme to run the plugin... to check if your function is registered properly, you can go to the procedure library (`Help > Procedure Browser`) or try running it in the console (`Filters > Python Fu > Console`). The thing is... all the plugins eventually gets "converted" into scheme functions. – ongspxm Jan 20 '17 at 01:59