GIMP Chat
http://gimpchat.com/

clear the layer below
http://gimpchat.com/viewtopic.php?f=9&t=17863
Page 1 of 1

Author:  Sweeney [ Fri Dec 13, 2019 9:20 am ]
Post subject:  clear the layer below

Hi,

I'd like to clear the layer below a layer before merging down in script-fu;

So far I have a small part working, but can't find a way to clear the layer below before merging down.
Could anyone help please?

Thanks


(define (mergeLetterDown img drawable)
(let*
(
(layerBelow 0)
(position 0)
)

(gimp-image-undo-group-start img)
(gimp-layer-set-opacity drawable 100)
;clear the layer below of all its contents?
(gimp-image-merge-down img drawable 2)
(gimp-displays-flush)
(gimp-image-undo-group-end img)
)
)

Author:  ofnuts [ Fri Dec 13, 2019 12:24 pm ]
Post subject:  Re: clear the layer below

You have to identify the layer below. One method is to iterate the layers, comparing the layer's id with the id if your reference layer, and when you reach it, iterate once more.

This said, clearing a layer is rather brutal, and merging layer X on a cleared layer should give you layer X. The only case where this is a bit different is the layers have a different size, but it can be more efficient to resize and offset layer X.

Author:  Sweeney [ Sat Dec 14, 2019 5:28 pm ]
Post subject:  Re: clear the layer below

Thanks ofnuts,

I was hoping for a simple solution.
But the challenging one exercised my brain.


;store a list of layers and get how many
(set! layers (gimp-image-get-layers img))
(set! layer_cnt (car layers))

;lets iterate through all the layers
(set! seq 0)
(while (< seq layer_cnt)
(set! loop_layer (aref (cadr layers) seq))

;did we match the active layer with the loop layer last time?
;if so lets clear it
(if (> match 0)
(begin
(gimp-edit-clear loop_layer)
(gimp-item-set-visible loop_layer TRUE)
(set! match 0)
)
()
);endif

;test to see if the current loop layer is the same as the active layer
;if it is set a flag to true
(if (equal? loop_layer drawable)
(begin
(set! match 1)
(gimp-item-set-visible loop_layer TRUE)
)
()
);endif

(set! seq (+ seq 1))
) ;end while


(set! seq (+ seq 1))
) ;end while

Author:  ofnuts [ Sun Dec 15, 2019 9:16 am ]
Post subject:  Re: clear the layer below

Hmm. Just found a simpler method: gimp-image-get-item-position() on the active layer, and increment that.

The whole thing can become tricky when you have layer groups.

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/