Gimp-Forum.net
Trouble with vector input for polygon selection - 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: Trouble with vector input for polygon selection (/Thread-Trouble-with-vector-input-for-polygon-selection)



Trouble with vector input for polygon selection - ss32 - 02-11-2018

I'm writing a plugin to call python-fu-heal-selection with inputs of the file and the points defining the polygon selection, but cannot get the polygon selection to work.  I have tried using the square polygon select and it works fine, but the generic polygon selection does not accept my input; what's wrong with my script?

Code:
(define
    (heal-select points point_count)
    
    (let*
        (
            (image         (car (gimp-file-load RUN-NONINTERACTIVE "tmp.jpg" "tmp.jpg")))
            (active-layer     (car (gimp-image-get-active-layer image)))            
        )                                            
        
        ;(gimp-image-select-rectangle     image CHANNEL-OP-ADD 122 67 138 81)    
        (set! active-layer (car (gimp-image-get-active-layer image)))    
        (define path-points (list->vector points))
        (gimp-image-select-polygon     image CHANNEL-OP-ADD point_count path-points)
        (python-fu-heal-selection     RUN-NONINTERACTIVE     
                                        image
                                        active-layer
                                        3
                                        0
                                        1)                                            
        (display points)
        (gimp-file-save RUN-NONINTERACTIVE image active-layer  "tmp2.jpg" "tmp2.jpg")
        (gimp-image-delete image)
    
    )
)

With the command line input:
Code:
gimp -i -b "(heal-select '(122. 67. 138. 67. 138. 81. 122. 81. 122. 67.) 5)" -b "(gimp-quit 0)"

I have tried removing '(define path-points (list->vector points))' and passed it the points as #(1 2 3  4) and still get an error message hinting at the fact that the polygon isn't closed or is empty.


RE: Trouble with vector input for polygon selection - Ofnuts - 02-11-2018

Warning: I starkly refuse to use 1950-era Scheme when I can use 1990-era Python for my Gimp scripts. But there are plenty of common things, so:

It appears that the doc (at least on the Python side...) is somewhat ambiguous. The 'length" parameter is really the plain length of the list of coordinates (which is also how all the other PDB calls work...), so if you have a polygon with 5 points, it should say "10". Note that you don't need to specify more than N pairs if the polygon has N summits, because Gimp will auto-close the polygon (so in your case, (122. 67. 138. 67. 138. 81. 122. 81.) 8) should work).


RE: Trouble with vector input for polygon selection - ss32 - 02-11-2018

Jesus, such a simple fix. I assumed it was 5 (x,y) pairs...