12-16-2024, 09:11 PM
(12-16-2024, 01:31 PM)Qhuenta Wrote: Ofnuts1. Depends if you work top down of bottom up
Code:
layers=image.layers[:] # Make a copy of the list
layers.reverse() # if working bottom up
Hi, I'm very new to scripting in Gimp and this is my first question, so I hope the age of the thread isn't an issue. Now, on to the question:
When I enter this code in the Python-Fu console window I do not see any list. Is the list that is referred to here supposed to be visible to the user? If so where or how can I see it?
In the Python console window you have to obtain the image. If there is only one image loaded in Gimp:
Code:
➤> image=gimp.image_list()[0]
Code:
➤> image=[img for img in gimp.image_list() if img.ID==11][0]
Do not use this technique in your scripts, it is just a useful cop-out in the Python console. In scripts you are normally given the image to work on.
Then with the image, image.layers is the list of the top-level layers and groups:
Code:
➤> image.layers
[<gimp.Layer 'Layer copy'>, <gimp.Layer 'Layer'>, <gimp.Layer 'Pasted Layer'>]
Code:
➤> image.layers[:] # copy of the list
[<gimp.Layer 'Layer copy'>, <gimp.Layer 'Layer'>, <gimp.Layer 'Pasted Layer'>]
➤> image.layers[::-1] # reversed copy of the list
[<gimp.Layer 'Pasted Layer'>, <gimp.Layer 'Layer'>, <gimp.Layer 'Layer copy'>]