2

How do I duplicate a layer at the script-fu (scheme) console?

Here is what I have done so far:

(gimp-image-list)

This tells me that the reference to my image is the number "1".

Next, I get a reference to the particular layer I want to duplicate:

(gimp-image-get-layer-by-name 1 "frame25")

The result of this tells me that the layer reference is the number "2".

I didn't see any functions for duplicating a layer, but I see that I can copy the layer and then insert it as a new layer.

(gimp-image-insert-layer 1 (car (gimp-layer-copy 2 TRUE)) 0 n)

But what is the value of n? I want to insert the duplicate right above the existing layer, the same as duplicating the layer would do in the Layers dock. But I haven't been able to find any functions that return the "position" (as the script-fu procedure browser calls the 4th parameter to gimp-image-insert-layer) of the layer in the stack. None of the "gimp-layer-get-*" functions, for instance, seem to refer to position. I have tried to search for this on the web, but most people use "position" to refer to the offset of the layer, which is a completely unrelated thing. (gimp-image-insert-layer 1 (gimp-layer-copy 2 TRUE) 0 n)

Michael
  • 9,060
  • 14
  • 61
  • 123

2 Answers2

0

Instead of n, put (car (gimp-image-get-item-position 1 2))

Or in general:

(car (gimp-image-get-item-position IMG LAYER))

Michael
  • 9,060
  • 14
  • 61
  • 123
0

n is the position of the layer in the layer stack, 0 being at the top (so to insert at the bottom, n is the current number of layers).

Note that if you write a true script, image and layer can be automatically passed as arguments (when there are several images in the list, it is difficult to tell which one the user is interested in, while the one in the arguments is the image the user is interacting with).

Also, if this is your first foray in Gimp scripting, don't overlook that you can write the scripts in Python (which is usually a lot easier).

xenoid
  • 8,396
  • 3
  • 23
  • 49