12-31-2024, 09:56 PM
(12-31-2024, 09:40 PM)origamifreak2 Wrote: I have a question. The gimp_drawable_type() function on line 9 is returning 0 for jpegs, 1 for pngs, and 1 for layer groups. How would I tell the difference between a single layer in a png file and a layer group? I'm probably missing something very simple here.
Code:
# make sure drawable is a layer
drawable_type = pdb.gimp_drawable_type(drawable)
if drawable_type != 0 and drawable_type != 1:
pdb.gimp_message(drawable_type)
pdb.gimp_message("Please select a layer")
return
gimp_drawable_type() isn't about Layer/Channel/Group but about color and alpha support, O being RGB and 1 beibg RGB+alpha.
To test the drawable "genre" you use Python classes with isinstance() with the caveat that a layer group is gimp.GroupLayer but since GroupLayer is a subclass of Layer, it is also a group. So typically:
Code:
if isinstance(drawable,gimp.Channel): # handles both channels and masks
complain_and_exit()
elif isinstance(drawable,gimp.GroupLayer): # is a group
process_group(drawable)
else: # should be a layer
process_layer(drawable)