Switch to full style
Post all Gimp scripts and script writing questions here
Post a reply

clear the layer below

Fri Dec 13, 2019 9:20 am

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)
)
)

Re: clear the layer below

Fri Dec 13, 2019 12:24 pm

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.

Re: clear the layer below

Sat Dec 14, 2019 5:28 pm

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

Re: clear the layer below

Sun Dec 15, 2019 9:16 am

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.
Post a reply