GIMP Python - Fill Path/Vector with color
up vote
0
down vote
favorite
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.
python gimp gimpfu
add a comment |
up vote
0
down vote
favorite
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.
python gimp gimpfu
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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.
python gimp gimpfu
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.
python gimp gimpfu
python gimp gimpfu
edited Nov 8 at 9:08
asked Nov 7 at 20:48
bpilling
1034
1034
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
It's a trap... pdb.gimp_image_get_vectors(image)
returns a list of integer ID for the paths, but the later calls require a gimp.Vectors
object.
image.vectors
is indeed a list of gimp.Vectors
and you can iterate all the paths with
for vector in image.vectors:
More problems:
- You declare two args in register() but have three in your function. In practice you don't need the path argument, since you aere going to iterate them all anyway.
- The layer argument of your function is the active layer when the plugin is called, and is normally the one you want to paint
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 context
CHANNEL-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:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from gimpfu import *
def plugin_main(image, layer):
for p in image.vectors:
pdb.gimp_image_select_item(image,CHANNEL_OP_REPLACE,p)
pdb.gimp_edit_fill(layer, FOREGROUND_FILL)
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>/Test/Fill all paths with average color",
"RGB*, GRAY*",
,
,
plugin_main
)
main()
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.
Thank you! I discovered the CHANNEL_OP_REPLACE needing underscores caused the script to not work, fixing this meant the script ran. The other points mentioned have been very helpful, thank you.
– bpilling
Nov 8 at 19:33
That wasn't the only thing I had to fix to make it run...
– xenoid
Nov 8 at 21:45
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
It's a trap... pdb.gimp_image_get_vectors(image)
returns a list of integer ID for the paths, but the later calls require a gimp.Vectors
object.
image.vectors
is indeed a list of gimp.Vectors
and you can iterate all the paths with
for vector in image.vectors:
More problems:
- You declare two args in register() but have three in your function. In practice you don't need the path argument, since you aere going to iterate them all anyway.
- The layer argument of your function is the active layer when the plugin is called, and is normally the one you want to paint
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 context
CHANNEL-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:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from gimpfu import *
def plugin_main(image, layer):
for p in image.vectors:
pdb.gimp_image_select_item(image,CHANNEL_OP_REPLACE,p)
pdb.gimp_edit_fill(layer, FOREGROUND_FILL)
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>/Test/Fill all paths with average color",
"RGB*, GRAY*",
,
,
plugin_main
)
main()
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.
Thank you! I discovered the CHANNEL_OP_REPLACE needing underscores caused the script to not work, fixing this meant the script ran. The other points mentioned have been very helpful, thank you.
– bpilling
Nov 8 at 19:33
That wasn't the only thing I had to fix to make it run...
– xenoid
Nov 8 at 21:45
add a comment |
up vote
1
down vote
accepted
It's a trap... pdb.gimp_image_get_vectors(image)
returns a list of integer ID for the paths, but the later calls require a gimp.Vectors
object.
image.vectors
is indeed a list of gimp.Vectors
and you can iterate all the paths with
for vector in image.vectors:
More problems:
- You declare two args in register() but have three in your function. In practice you don't need the path argument, since you aere going to iterate them all anyway.
- The layer argument of your function is the active layer when the plugin is called, and is normally the one you want to paint
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 context
CHANNEL-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:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from gimpfu import *
def plugin_main(image, layer):
for p in image.vectors:
pdb.gimp_image_select_item(image,CHANNEL_OP_REPLACE,p)
pdb.gimp_edit_fill(layer, FOREGROUND_FILL)
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>/Test/Fill all paths with average color",
"RGB*, GRAY*",
,
,
plugin_main
)
main()
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.
Thank you! I discovered the CHANNEL_OP_REPLACE needing underscores caused the script to not work, fixing this meant the script ran. The other points mentioned have been very helpful, thank you.
– bpilling
Nov 8 at 19:33
That wasn't the only thing I had to fix to make it run...
– xenoid
Nov 8 at 21:45
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
It's a trap... pdb.gimp_image_get_vectors(image)
returns a list of integer ID for the paths, but the later calls require a gimp.Vectors
object.
image.vectors
is indeed a list of gimp.Vectors
and you can iterate all the paths with
for vector in image.vectors:
More problems:
- You declare two args in register() but have three in your function. In practice you don't need the path argument, since you aere going to iterate them all anyway.
- The layer argument of your function is the active layer when the plugin is called, and is normally the one you want to paint
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 context
CHANNEL-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:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from gimpfu import *
def plugin_main(image, layer):
for p in image.vectors:
pdb.gimp_image_select_item(image,CHANNEL_OP_REPLACE,p)
pdb.gimp_edit_fill(layer, FOREGROUND_FILL)
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>/Test/Fill all paths with average color",
"RGB*, GRAY*",
,
,
plugin_main
)
main()
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.
It's a trap... pdb.gimp_image_get_vectors(image)
returns a list of integer ID for the paths, but the later calls require a gimp.Vectors
object.
image.vectors
is indeed a list of gimp.Vectors
and you can iterate all the paths with
for vector in image.vectors:
More problems:
- You declare two args in register() but have three in your function. In practice you don't need the path argument, since you aere going to iterate them all anyway.
- The layer argument of your function is the active layer when the plugin is called, and is normally the one you want to paint
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 context
CHANNEL-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:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from gimpfu import *
def plugin_main(image, layer):
for p in image.vectors:
pdb.gimp_image_select_item(image,CHANNEL_OP_REPLACE,p)
pdb.gimp_edit_fill(layer, FOREGROUND_FILL)
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>/Test/Fill all paths with average color",
"RGB*, GRAY*",
,
,
plugin_main
)
main()
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.
answered Nov 8 at 14:30
xenoid
2,4582820
2,4582820
Thank you! I discovered the CHANNEL_OP_REPLACE needing underscores caused the script to not work, fixing this meant the script ran. The other points mentioned have been very helpful, thank you.
– bpilling
Nov 8 at 19:33
That wasn't the only thing I had to fix to make it run...
– xenoid
Nov 8 at 21:45
add a comment |
Thank you! I discovered the CHANNEL_OP_REPLACE needing underscores caused the script to not work, fixing this meant the script ran. The other points mentioned have been very helpful, thank you.
– bpilling
Nov 8 at 19:33
That wasn't the only thing I had to fix to make it run...
– xenoid
Nov 8 at 21:45
Thank you! I discovered the CHANNEL_OP_REPLACE needing underscores caused the script to not work, fixing this meant the script ran. The other points mentioned have been very helpful, thank you.
– bpilling
Nov 8 at 19:33
Thank you! I discovered the CHANNEL_OP_REPLACE needing underscores caused the script to not work, fixing this meant the script ran. The other points mentioned have been very helpful, thank you.
– bpilling
Nov 8 at 19:33
That wasn't the only thing I had to fix to make it run...
– xenoid
Nov 8 at 21:45
That wasn't the only thing I had to fix to make it run...
– xenoid
Nov 8 at 21:45
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53197572%2fgimp-python-fill-path-vector-with-color%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown