I am trying to develop a script that i can run on opened SVG files. I want to iterate over all paths and fill the path with an arbitrary color ( I will be replacing this part of the code later). The first stage of this is just iterating over the paths, and I cannot seem to figure out how to do this. My code is below - why am I not seeing any paths being iterated over?
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from gimpfu import *
def plugin_main(image, layer, path):
vectors_count, vectors = pdb.gimp_image_get_vectors(image)
for n in vectors:
pdb.gimp_image_select_item(image,CHANNEL-OP-REPLACE,n)
foreground = pdb.gimp_context_get_foreground()
pdb.gimp_edit_fill(image.layers[0], foreground)
register(
"create_polygon_art",
"Fills all the paths with the average color within path",
"Fills all the paths with the average color within path",
"Bryton Pilling",
"Bryton Pilling",
"2018",
"<Image>/Filters/Fill all paths with average color",
"RGB*, GRAY*",
[],
[],
plugin_main
)
main()
I have also tried a number of different approaches I have found by googling, including using something simpler for the iteration like:
for v in gimp.Vectors
But no matter what I try I cannot seem to get evidence of an iteration over the paths.
I am using gimp 2.10.6 on Windows 10 64-bit.
It's a trap...
pdb.gimp_image_get_vectors(image)
returns a list of integer ID for the paths, but the later calls require agimp.Vectors
object.image.vectors
is indeed a list ofgimp.Vectors
and you can iterate all the paths withMore problems:
gimp-edit-fill
takes a color source and not a color. When you go further with your code you will have to set the foreground color, and push/pop the contextCHANNEL-OP-REPLACE
isn't a valid Python symbol, in Python you should useCHANNEL_OP_REPLACE
(with underscores)Two collections of python scripts here and there.
If you are under Windows, some hints to debug your scripts here
Your code with fixes:
You can make you code more user-friendly by painting "strokes" (so you have one path with several strokes). If you want individual selections on strokes, you can copy them to a temporary path. Code for this can be found in some scripts in the collections above.