Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help! Python loop for the mentally challenged.
#2
If the channels named 0 to 9 are the only channels in the image, you can iterate on a copy of the channels list:

Code:
for channel in image.channels[:]:
 pdb.gimp_image_select_item(image, CHANNEL_OP_REPLACE, channel)
 layer_add = pdb.gimp_layer_new_from_drawable(layer, image)
 pdb.gimp_image_insert_layer(image, layer_add, None, 0)
 pdb.gimp_item_set_name(layer_add, channel.name)
 mask = pdb.gimp_layer_create_mask(layer_add, ADD_MASK_SELECTION)
 pdb.gimp_layer_add_mask(layer_add, mask)
 pdb.gimp_image_remove_channel(image, channel)
image.channels gives the list of channels in the image.
image.channels[:] creates a copy of that list (since you delete the channel at the end of the loop, you need to work on a copy of the list)
channel.name gives the name of the channel as string
Reply


Messages In This Thread
RE: Help! Python loop for the mentally challenged. - by tmanni - 09-11-2020, 05:21 PM

Forum Jump: