RSS/Atom feed Twitter
Site is read-only, email is disabled

Set active layer by referring to its name

This discussion is connected to the gimp-user-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.

This is a read-only list on gimpusers.com so this discussion thread is read-only, too.

4 of 4 messages available
Toggle history

Please log in to manage your subscriptions.

Set active layer by referring to its name professor_ 20 Aug 10:40
  Set active layer by referring to its name saulgoode@flashingtwelve.brickfilms.com 20 Aug 23:31
   Set active layer by referring to its name Joao S. O. Bueno 26 Aug 05:18
    Set active layer by referring to its name Joao S. O. Bueno 26 Aug 05:28
2009-08-20 10:40:01 UTC (over 14 years ago)
postings
2

Set active layer by referring to its name

Hello!

When using Gimp interactively, I can assign names to the different layers, e.g. "p1", "p2", "p3" etc.

Now, is it possible to set a layer active by referring to its name? E.g.:

gimp-image-set-active-layer "p1" ?

Thanks a lot! Sabine

Sabine

saulgoode@flashingtwelve.brickfilms.com
2009-08-20 23:31:02 UTC (over 14 years ago)

Set active layer by referring to its name

Quoting professor :

When using Gimp interactively, I can assign names to the different layers, e.g. "p1", "p2", "p3" etc.

Now, is it possible to set a layer active by referring to its name? E.g.:

gimp-image-set-active-layer "p1" ?

You will have to manually search the list of layers for the one with the matching name.

The following function will do so for a given image, returning the layerID (or "0" if not found).

(define (find-layer-by-name image s) (let* (
(layer's (vector->list (cadr (gimp-image-get-layers image)))) (found 0)
)
(while (pair? layer's)
(if (string=? s (car (gimp-layer-get-name (car layer's)))) (set! found (car layer's))
)
(set! layer's (cdr layer's))
)
found
)
)

Joao S. O. Bueno
2009-08-26 05:18:29 UTC (over 14 years ago)

Set active layer by referring to its name

On Thursday 20 August 2009, saulgoode@flashingtwelve.brickfilms.com wrote:

Quoting professor :

When using Gimp interactively, I can assign names to the different layers, e.g. "p1", "p2", "p3" etc.

Now, is it possible to set a layer active by referring to its name? E.g.:

gimp-image-set-active-layer "p1" ?

You will have to manually search the list of layers for the one with the matching name.

The following function will do so for a given image, returning the layerID (or "0" if not found).

(define (find-layer-by-name image s) (let* (
(layer's (vector->list (cadr (gimp-image-get-layers image)))) (found 0)
)
(while (pair? layer's)
(if (string=? s (car (gimp-layer-get-name (car layer's)))) (set! found (car layer's))
)
(set! layer's (cdr layer's))
)
found
)
)

Huh???ah, You mean:

def find_layer_by_name (image, name): for layer in image:
if layer.name == name:
return layer
return None

(yes, this is the actual python code for it, not pseudo-code) you just need a proper register call to have it as a gimp-plugin

Scheme was great for its time - when computers could not hold interpreters mroe complex than what is needed to handle scheme. Scheme may still be usefull -and look great - for people who already hae it flowing in their veins. But the truth is that for very single problems one have to go through a lot of work around to get to the core of it. One of the ideas of Python, as a very high level language is not to stay between you and the problem, as you can see by the snippet above.

js
->

Joao S. O. Bueno
2009-08-26 05:28:54 UTC (over 14 years ago)

Set active layer by referring to its name

Sorry -- there was an error in my python function

On Wednesday 26 August 2009, Joao S. O. Bueno wrote:

Huh???ah, You mean:

def find_layer_by_name (image, name):

-> for layer in image:
+ for layer in image.layers:

if layer.name == name:
return layer
return None

That is the correct version.

js
->