如何获得路径刀具点的坐标?

2024-06-25 23:57:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我不熟悉gimp python-fu编程 我花了4天的时间没有找到最合适的函数来获得绘制路径的坐标,并在gtk消息框中显示输出,如下图所示。在

enter image description here

请考虑我是在windows机器上开发的

我试过这样的代码:

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()

有时插件本身不显示在菜单中,有时根本没有输出。在


Tags: imageimportgtkgetpdbdialogstrgimp
1条回答
网友
1楼 · 发布于 2024-06-25 23:57:10

我一直在Ubuntu中测试这个问题(我知道它不一样)。但是,您的代码没有输出任何内容,所以我至少能够重现问题的这一部分。在

您的函数具有以下声明头:

def python_fu_mahdicoordinates(image, layer):

因此,register应该这样调用:

^{pr2}$

在更改列表中,必须声明函数需要处理的参数。在你的例子中,图像和图层。这对我有用。在

我不知道为什么插件有时不出现在菜单中,但是尝试用你想要的任何名称来声明menu= "<Image>/YourNewMenu"。这应该会在菜单栏中生成一个新菜单,并且可能会完全解决您的问题。值得一试。在

我希望这有帮助。在

相关问题 更多 >