Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gimp: How can I get the coordinates of path tool points?

I am new to gimp python-fu programming I have spent my 4 days WITH NO LUCK to figure out which is the best appropriate functions to use in order to get the coordinates of drawn path and show the output on gtk message box like the following image.

enter image description here

Please consider that I develop on windows machine

I have tried my code like this:

import gtk, gimpui
from gimpfu import *

def debugMessage(Message):
    dialog = gtk.MessageDialog(None, 0, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, Message)
    dialog.run()
    dialog.hide()

def python_fu_mahdicoordinates(image, layer):
    vectors = pdb.gimp_image_get_active_vectors(image)
    nstrokes, strokes = pdb.gimp_vectors_get_strokes(vectors)
    stroke_type, n_points, cpoints, closed = pdb.gimp_vectors_stroke_get_points(vectors, strokes[0])
    x0 = cpoints[0]
    y0 = cpoints[1]
    x1 = cpoints[6]
    y1 = cpoints[7]
    x2 = cpoints[12]
    y2 = cpoints[13]
    x3 = cpoints[18]
    y3 = cpoints[19]
    debugMessage('(' + str(x0) + ', ' + str(y0) + ', '+str(x1) + ', '+str(y1) + ', '+str(x2) + ', '+str(y2) + ', '+str(x3) + ', '+str(y3) + ')')

    return

register(
    "python_fu_mahdicoordinates",
    "Mahdi Cooridnates",
    "Get Cooridnates of any path",
    "Mahdi Alkhatib", "Mahdi Alkhatib", "2016",
    "Mahdi Cooridnates...",
    "*",
    [],
    [],
    python_fu_mahdicoordinates,
    menu= "<Image>/Tools/Misc")

main()

Sometimes the plugin itself does not show in the menu, sometimes no output at all.

like image 967
Mahdi Alkhatib Avatar asked Jan 24 '16 07:01

Mahdi Alkhatib


1 Answers

I have been testing this issue in Ubuntu (I know it isn't the same). However, your code didn't output anything, so I was able to reproduce at least this part of the problem.

Your function has got this declaring header:

def python_fu_mahdicoordinates(image, layer):

So, registershould be called like this:

register(
    "python_fu_mahdicoordinates",
    "Mahdi Cooridnates",
    "Get Cooridnates of any path",
    "Mahdi Alkhatib", "Mahdi Alkhatib", "2016",
    "Mahdi Cooridnates...",
    "*",
    [
        (PF_IMAGE, "image", "takes current image", None),
        (PF_LAYER, "layer", "takes current layer", None),
    ],
    [],
    python_fu_mahdicoordinates,
    menu= "<Image>/YourNewMenu")

In the changed list, parameters your function needs to process have to be declared. In your case, image and layer. This works for me.

I don't know why the plugin doesn't appear in your menu sometimes, but try to declare menu= "<Image>/YourNewMenu" with any name you want. This should spawn a new menu in the menubar, and probably will solve entirely your problem. It's worth to try.

I hope this helps.

like image 171
SebasSBM Avatar answered Nov 03 '22 04:11

SebasSBM