RubisDrake wrote:
Hey, thanks a lot for your help, ofnuts!
I figured out that it worked without enumerate(), probably because layerOrGroup.mode is expecting a tuple instead of an enum object? I'm no Python wizard, but maybe.
The error was this:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "<input>", line 3, in process
AttributeError: 'tuple' object has no attribute 'mode'
Anyway, final solution here that worked for me, thanks to ofnuts:
def process(parent):
for layerOrGroup in parent.layers:
layerOrGroup.mode=LAYER_MODE_NORMAL
if isinstance(layerOrGroup,gimp.GroupLayer):
process(layerOrGroup)
image=gimp.image_list()[0]
process(image)
Again, you could probably loop through gimp.image_list()[n] using index n, but this works great for now!
Yes, sorry I left the enumerate in from the code I copied.
This is pythin you don't need to iterate list using the index, to iterate the images you just do:
for image in gimp.image_list():
.. do whatever
and in fact if you need the image index, you use enumerate():
for index,image in enumerate(gimp.image_list()):
.. do whatever with index
... because in Python accessing an arbitrary element in a list (list[n]) is more expensive than from an element to the next (in python, arrays are simulated with lists when in other languages, lists are implemented with arrays under the hood). enumerate() also lets you set a an origin, so you can enumerate from 0 or from 1 (or from 58...).