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.










share|improve this question




























    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.










    share|improve this question


























      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.










      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 8 at 9:08

























      asked Nov 7 at 20:48









      bpilling

      1034




      1034
























          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 use CHANNEL_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.






          share|improve this answer





















          • 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











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          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

























          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 use CHANNEL_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.






          share|improve this answer





















          • 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















          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 use CHANNEL_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.






          share|improve this answer





















          • 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













          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 use CHANNEL_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.






          share|improve this answer












          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 use CHANNEL_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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          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


















          • 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


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          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





















































          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







          這個網誌中的熱門文章

          Hercules Kyvelos

          Tangent Lines Diagram Along Smooth Curve

          Yusuf al-Mu'taman ibn Hud