Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
GIF frames deleting script.
#10
(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]
If there are several images, you can find the image ID in the title bar (usually followed by .0, for instance 11.0 (the 0 is a view ID, not relevant here))
Code:
➤> image=[img for img in gimp.image_list() if img.ID==11][0]
In slow-mo: [img for img in gimp.image_list() if img.ID==11] constructs  a list of all images with the required id (only one...), and the [0] extracts the first and only image form the list.

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'>]
and:
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'>]
Reply


Messages In This Thread
GIF frames deleting script. - by rey - 04-02-2023, 12:29 PM
RE: GIF frames deleting script. - by rey - 04-03-2023, 10:05 AM
RE: GIF frames deleting script. - by Ofnuts - 04-03-2023, 02:41 PM
RE: GIF frames deleting script. - by Qhuenta - 12-16-2024, 01:31 PM
RE: GIF frames deleting script. - by Ofnuts - 12-16-2024, 09:11 PM
RE: GIF frames deleting script. - by rey - 04-03-2023, 05:18 PM
RE: GIF frames deleting script. - by Ofnuts - 04-03-2023, 09:23 PM
RE: GIF frames deleting script. - by teapot - 04-04-2023, 03:30 AM
RE: GIF frames deleting script. - by Ofnuts - 04-04-2023, 07:26 AM
RE: GIF frames deleting script. - by teapot - 04-05-2023, 02:21 AM

Forum Jump: