3

I have a simple problem that's stumping me in GIMP Script-fu and procedural browser.

I'm trying to move a layer up/down in an image which has 40 layers. Let us call the image test.xcf and the said layer Chromask-snapshot.

  1. NOTE : The layer X Y offsets are NOT what are being changed.
  2. I desire to shift a single layer to whatever position I need on the layer list of test.xcf.

For eg. I set many layers' visibility to 0 in my text.xcf. Then I take a snapshot using gimp-layer-new-from-visible and add the layer to Now HERE is the problem The function accepts my string (passed as new layer's name) and faithfully takes a snapshot and sticks it at the top of the layer list with the name I have specified.

I dont want it there i.e. in the default position on the top of the layers list in the image. I need it to be in position 11 or 37 or whatever ( as an example ).

I have failed to find a procedural solution by which I take a layer in the image stack and move it up or down as I desire.

sigh

All your comments are deeply appreciated.

2 Answers2

3

After taking the snapshot, you have to add it to the target image and for this both the deprecated gimp-image-add-layer() and the new gimp-image-insert-layer() take a layer position as the last parameter (0 is top of stack).

And you have the whole set of gimp-image-raise-item(), gimp-image-lower-item(), gimp-image-raise-item-to-top(), gimp-image-lower-item-to-bottom(), should you want to adjust the position later.

xenoid
  • 8,396
  • 3
  • 23
  • 49
  • The gimp-image-insert-layer() does have both parent and position. Just what I needed ! The raise and lower functions stepping one layer at a time are very useful too.I appreciate your time in responding to my question. – user3103574 Sep 27 '16 at 16:09
  • Where do you find these function names, can I find the documentation for this somewhere? I can't find any mention of the functions you mention on https://www.gimp.org/docs/python/index.html – BdR May 29 '22 at 21:43
  • `Filters > Python-fu > Console`, then hit the `Browse..." button and use the search bar. This is an auto-generated doc, so even additional plugins are included. All calls available to `script-fu` have their `python-fu` counterpart. – xenoid May 29 '22 at 21:57
2

Just use the gimp-image-reorder-item call - pass None (-1 in tiny-fu) as the Parent parameter.

(And unless you are already proficient in List/Scheme - or learning these are part of your objecttives - I'd recomend scripting in Python instead of tiny-fu)

jsbueno
  • 99,910
  • 10
  • 151
  • 209
  • The gimp-image-reorder-item is fantastic for my existant layers for any possible position shifts - well the bonus you gave shown is that I can also move i.e. re-order in between sub trees in the image. Thanks this is very very helpful. I appreciate your time in responding to my question. I am wearying of script-fu. Its tedious. Can you suggest a couple of first steps in starting off with python-fu ? – user3103574 Sep 27 '16 at 16:17
  • Where are you finding these API function names? Is there documentation somewhere? When I search on Google for `gimp-image-reorder-item` the top result is this stackoverflow question. – BdR May 29 '22 at 21:40
  • In GIMP's help menu, or straight from GIMP's Python console "Browse..." button. – jsbueno May 29 '22 at 22:11