Python Gimp:如何获得路径刀具点的坐标?
我是gimp python编程新手 为了获得绘制路径的坐标并在gtk消息框上显示输出(如下图所示),我花了4天的时间没有找到最合适的函数 请考虑我在Windows机器上开发 我尝试过这样的代码:Python Gimp:如何获得路径刀具点的坐标?,python,gimp,python-fu,gimpfu,Python,Gimp,Python Fu,Gimpfu,我是gimp python编程新手 为了获得绘制路径的坐标并在gtk消息框上显示输出(如下图所示),我花了4天的时间没有找到最合适的函数 请考虑我在Windows机器上开发 我尝试过这样的代码: import gtk, gimpui from gimpfu import * def debugMessage(Message): dialog = gtk.MessageDialog(None, 0, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, Message)
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()
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")
导入gtk,gimpui
从gimpfu进口*
def调试消息(消息):
dialog=gtk.MessageDialog(无,0,gtk.MESSAGE\u信息,gtk.BUTTONS\u确定,消息)
dialog.run()
dialog.hide()
定义python_fu_Mahdico坐标(图像,层):
向量=pdb.gimp\u图像\u获取活动\u向量(图像)
n笔划,笔划=pdb。gimp_向量_获取_笔划(向量)
笔划类型,n点,C点,闭合=pdb。gimp向量笔划获取点(向量,笔划[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]
调试消息(“(“+str(x0)+”、“+str(y0)+”、“+str(x1)+”、“+str(y1)+”、“+str(x2)+”、“+str(y2)+”、“+str(x3)+”、“+str(y3)+”))
返回
登记册(
“python_fu_mahdicordinates”,
“Mahdi Cooridates”,
“获取任何路径的Cooridate”,
“Mahdi Alkhatib”、“Mahdi Alkhatib”、“2016年”,
“Mahdi Cooridates…”,
"*",
[],
[],
python_fu_Mahdicordinates,
菜单=“/Tools/Misc”)
main()
有时插件本身不会显示在菜单中,有时根本没有输出。我一直在Ubuntu中测试这个问题(我知道它不一样)。但是,您的代码没有输出任何内容,因此我至少能够重现问题的这一部分 您的函数具有以下声明标头:
def python_fu_mahdicoordinates(image, layer):
因此,register
应该这样调用:
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()
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")
寄存器(
“python_fu_mahdicordinates”,
“Mahdi Cooridates”,
“获取任何路径的Cooridate”,
“Mahdi Alkhatib”、“Mahdi Alkhatib”、“2016年”,
“Mahdi Cooridates…”,
"*",
[
(PF_图像,“图像”,“获取当前图像”,无),
(PF_层,“层”,“取当前层”,无),
],
[],
python_fu_Mahdicordinates,
menu=“/YourNewMenu”)
在已更改列表中,必须声明函数需要处理的参数。在您的情况下,图像和图层。这对我有用
我不知道为什么插件有时不出现在您的菜单中,但请尝试使用您想要的任何名称声明menu=“/YourNewMenu”
。这将在菜单栏中产生一个新菜单,可能会完全解决您的问题。值得一试
我希望这有帮助