GIMP3,python Gimp.get_pdb().lookup_procedure('gimp-path-stroke-get-points')

I have a simple image with a 2 point path (just a straight line).

I want to get the two end-points using Gimp.get_pdb().lookup_procedure(‘gimp-path-stroke-get-points’).

This is what I do so far in the console:

from gi.repository import Gimp

image = Gimp.get_images()[0]
layers = image.get_layers()
layer = layers[0]

Gimp.Item.get_name(layer)  # verify correct image

vectors = Gimp.Image.get_paths(image)
vector = vectors[0]
print(Gimp.Item.get_name(vector))  # verify path

strokes = Gimp.Path.get_strokes(vector)
stroke = strokes[0]  # int

procedure = Gimp.get_pdb().lookup_procedure('gimp-path-stroke-get-points')
config = procedure.create_config()
config.set_property('path', vector)
config.set_property('stroke-id', stroke)
result = procedure.run(config)
success = result.index(0)
type_ = result.index(1)
controlpoints = result.index(2)  # GimpDouble Array!
closed = result.index(3)

After that … how do I obtain the points’ coordinates? (x = , y = ?)

I can’t handle controlpoints like normal arrays … so how is it done?

Hi! You don’t need to use the PDB - you can just call it from the vector object:

points = vector.stroke_get_points(stroke)
points.controlpoints

1 Like

Thanks, that works.

But what are all these points? I get

[180.0, 188.0, 180.0, 188.0, 180.0, 188.0, 436.0, 188.0, 436.0, 188.0, 436.0, 188.0]

I only expected 2 pairs of x,y points. What is the rest?

PS.: the pdb does not work?

When I try, I get this:

>>> result.index(2)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
AttributeError: 'gobject.GBoxed' object has no attribute '__module__'. Did you mean: '__reduce__'?

The PDB works well (the function you use instead uses the PDB), it’s the binding which likely doesn’t know how to handle such boxed types. There may be something fixable on our side, or maybe not. Sometimes it needs to be fixed on the binding side (PyGObject for Python). Can’t say for sure. We’d need to look at such things more closely. :person_shrugging:

In any case, there are usually no reasons whatsoever to use the PDB directly for any of the libgimp functions. The latter are much more practical to use.

The PDB are much more useful for all PDB procedures which don’t have an associated function, i.e. all the PDB procedures created by plug-ins (allowing one plug-in to call another).

Thanks for your reply. Still curious what all these numbers are.

I would have expected 2 pairs of x,y points. Why do I get 6 pairs of them?

It probably also includes the Bezier curve control points for that part of the path (what you can use to make it curved).

1 Like