GIMP 2.10.32 Python-Fu - Printable Version +- Gimp-Forum.net (https://www.gimp-forum.net) +-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP) +--- Forum: Extending the GIMP (https://www.gimp-forum.net/Forum-Extending-the-GIMP) +---- Forum: Scripting questions (https://www.gimp-forum.net/Forum-Scripting-questions) +---- Thread: GIMP 2.10.32 Python-Fu (/Thread-GIMP-2-10-32-Python-Fu) |
GIMP 2.10.32 Python-Fu - alecpepe - 07-25-2022 I have successfully written a script, which when ran in the Python-Fu console does what I want. I want to make a keyboard shortcut, so I can run this quickly when necessary, rather than pasting it into the console every time. How should I do this? I've tried writing the code in VS code and saving it in the GIMP scripts folder as both a .py and .scm file. The .scm file raises 'unbound variable: import' when I hit 'refresh scripts' under Script-Fu. I cannot find where to run the script as a .py, but it seems to refresh fine. I also do not know how I would bind a keyboard shortcut to a script. Here's the code, though I doubt this is the issue as it works fine in the console: import gimpfu current_image = gimp.image_list()[0] layer=pdb.gimp_layer_new(current_image, 1, 1, gimpfu.RGB_IMAGE, "white_layer", 100, gimpfu.NORMAL_MODE) pdb.gimp_image_add_layer(current_image, layer, 0) pdb.gimp_layer_resize_to_image_size(layer) pdb.gimp_item_set_visible(layer, 0) RE: GIMP 2.10.32 Python-Fu - Ofnuts - 07-25-2022 To make you code a real "script": 1) Since it's Python it is technically no a script, but a plugin so it goes in the "plug-ins", directory 2) It has to "register" to make it known to Gimp. This means declaring a procedure, the parameter types, the menu position, the kind of images it can work on, and miscellaneous metadata (author...) So your code ends up looking like this: Code: # Preferred form of import, avoids "gimpfu" prefixes all over. When your code registers correctly, the menu entry appears at the bottom of the Layer menu. You can then edit the keyboard shortcuts and search the add-white-layer identifier to assign a shortcut: [attachment=8399]
|