It is currently Sun Jun 30, 2024 3:06 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: clear the layer below
PostPosted: Fri Dec 13, 2019 9:20 am  (#1) 
Offline
GimpChat Member
User avatar

Joined: Mar 27, 2015
Posts: 22
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)
)
)


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: clear the layer below
PostPosted: Fri Dec 13, 2019 12:24 pm  (#2) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4752
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.

_________________
Image


Top
 Post subject: Re: clear the layer below
PostPosted: Sat Dec 14, 2019 5:28 pm  (#3) 
Offline
GimpChat Member
User avatar

Joined: Mar 27, 2015
Posts: 22
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


Top
 Post subject: Re: clear the layer below
PostPosted: Sun Dec 15, 2019 9:16 am  (#4) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4752
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.

_________________
Image


Top
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Clear skyes, Pappy

0

No new posts Attachment(s) Adding a image as a layer, moving layer, and then flattening

2

No new posts How do I script a new white layer to the bottom of the layer stack

7

No new posts Shortcuts to 2.10 documentation re: Layer & Layer-group modes

0

No new posts Add layer mask hides the entire layer

3



* Login  



Powered by phpBB3 © phpBB Group