1

How can I get the list of items in an image using python-fu? I've tried searching for a similar function in Python Procedure Browser and google but I couldn't find any. (My end goal is to select a text item on a layer and convert it to a path)

Edit - Using GIMP version 2.8.2 on macOS Mojave

Akash Agarwal
  • 2,326
  • 1
  • 27
  • 57

1 Answers1

4

You don't list "items" in general. You list layers, channels, or paths, either using the PDB:

for lid in pdb.gimp_image_get_layers(image)
for cid in pdb.gimp_image_get_channels(image)
for vid in pdb.gimp_image_get_vectors(image)

or the attributes of the image object:

for l in image.layers
for c in image.channels
for v in image.vectors

The PDB calls return integer item IDs (use gimp._id2drawable(id)/gimp._id2vectors(id) to get the objects), while the image attributes are lists of gimp.Layer/gimp.Channel/gimp.Vector objects (and are therefore much simpler to work with).

To tell if a layer is a text layer, you have to use a PDB call: pdb.gimp_item_is_text_layer(layer)

You can iterate the text layers thus

for textlayer in [l for l in image.layers if pdb.gimp_item_is_text_layer(l)]`

To get the path from a text layer:

path=pdb.gimp_vectors_new_from_text_layer(image,layer)

Many sample Python scripts here and some more specialized in paths here.

xenoid
  • 8,396
  • 3
  • 23
  • 49