GIMP 2.99/ Python3 How to access bottom layer of image

How do I access the bottom layer of an image.

I used to do something like this in GIMP 2.10.x:

    layers = image.layers
    bottom_layer = image.layers[len(layers) - 1]

What’s the equivalent in GIMP 2.99?

1 Like

From file-openraster.py:

    layer_stack = image.list_layers()
    # Number of top level layers for tracking progress
    lay_cnt = len(layer_stack)
1 Like

Thank you. That’s what I needed.

1 Like

In Python you can use negative indexes to access the end of a list, so

 bottom_layer = image.layers[len(layers) - 1]

is better written as:

bottom_layer = image.layers[-1]
1 Like

Oh sure, yes.
Sometimes I’m thinking too complicated. Thanks for the tip.

1 Like

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.