Gimp-Forum.net
Python Fu: Creating batch path loading and saving plugin. - 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: Python Fu: Creating batch path loading and saving plugin. (/Thread-Python-Fu-Creating-batch-path-loading-and-saving-plugin)



Python Fu: Creating batch path loading and saving plugin. - JeBe - 10-31-2018

Hi, this is my first post and I hope it’s correctly written.

My ability to write scripts in Python Fu is very restricted, I have no other knowledge of “general” programing. I did adjust a .py plugin so that my workflow in GIMP 2.8.22 under windows 10 is a bit faster. It’s an automated version of “color to alpha”, name and function is “black to alpha”.

I would like to create a Plugin in Python Fu with interface: It should have PF_DIRNAME for the opening path, and one for the saving path.

Opening path should load all (.tga) files in the interface directory path folder and its subfolders. For each subfolder and its (.tga) files it needs to make .xcf and save this based on the name of the folder and then the subfolder in a selected saving path.

Example: folder name “Gimp” Subfolder name “01”= “Gimp01.xcf”, 
“Gimp01.xcf”, “Gimp02.xcf”, etc...

“Gimp01.xcf” needs to contain the (.tga) files from the subfolder and loads the lowest file number in the highest in layer.

Example: “image0000” and “image 0525” are in subfolder. “image0000” needs to be above “image0525” in the “Gimp01.xcf”

For each image per .xcf it needs to run “black to alpha”.

I hope this is possible with Python-Fu. And if I could get some guidance.

JeBe


RE: Python Fu: Creating batch path loading and saving plugin. - Ofnuts - 10-31-2018

Yes, it is doable. Steep learning curve if you need to learn both Python and Gimp scripting. Some hints:
  • Use os.walk(topdir) to list the contents of the top directories. This produces sperat lists of directories and files
  • All the API documentation is available via Filters>Python-fu>Console>Browse.... It is dynamically generated, you'll even see your black-to-alpha plugin there.
  • The Python-specific bit of the API (using Python ibjects instead of the PDB calls) is documented here: http://www.gimp.org/docs/python/index.html
  • Load the files with layer=pdb.gimp_file_load_layer(image, filename). Once loaded you have to explicitly add the layer to the image (image.add_layer(layer,pos), pos=0 for the top of the stack, pos=len(image.layers) for the bottom).
  • You can make a special case and load the first file with image=pdb.gimp_file_load(filename,filename) to create the image.
  • Try to get at least the file walk working by using Python outside of Gimp (you can run the python executable that comes with Gimp in a terminal/console, it is much easier to debug that way, but this is only possible for code that doesn't interact with Gimp).
  • To debug under Gimp, several hints there: https://www.gimp-forum.net/Thread-Debugging-python-fu-scripts-in-Windows
  • As long as you don't change the registration data, you can modify the script file and execute the new version without needing to restart Gimp.
Good luck.


RE: Python Fu: Creating batch path loading and saving plugin. - JeBe - 11-07-2018

Thanks for the advice, i am still a long way from creating my plugin, I did find your “Flatten visible layers group…” plugin and it’s saving me a lot of work.