Gimp-Forum.net
Delete Layer? - Printable Version

+- Gimp-Forum.net (https://www.gimp-forum.net)
+-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP)
+--- Forum: Extending the GIMP (https://www.gimp-forum.net/Forum-Extending-the-GIMP)
+---- Forum: Scripting questions (https://www.gimp-forum.net/Forum-Scripting-questions)
+---- Thread: Delete Layer? (/Thread-Delete-Layer)



Delete Layer? - DaltonCalford - 11-29-2022

Hi Everyone, I have been learning script-fu but have hit a roadblock.

I have a script-fu script that works perfectly except that is will not delete a layer.

Here is the script, minus the variables so that it is easy to run in a console.
The script is written to run on an image with an image id of "1" so you may need to adjust depending upon your current environment.

 ((gimp-selection-none 1)
 (gimp-item-set-visible (car(gimp-image-get-layer-by-name 1  "background" )) 1)
 (gimp-image-set-active-layer 1 (car(gimp-image-get-layer-by-name 1  "background" )))
 (gimp-image-insert-layer 1 (car (gimp-layer-new-from-drawable (car(gimp-image-get-active-drawable  1))  1)) 0 0 )
 (gimp-image-set-active-layer 1 (car(gimp-image-get-layer-by-name 1  "background copy" )))
 (gimp-image-select-color 1 0  (car(gimp-image-get-layer-by-name 1  "1.png" )) '(0 0 0))
 (script-fu-add-bevel 1 (car(gimp-image-get-layer-by-name 1  "background copy" ))  5 0 0 )
 (script-fu-add-bevel 1 (car(gimp-image-get-layer-by-name 1  "background copy" ))  5 0 0 )
 (gimp-selection-invert 1)
 (gimp-drawable-edit-clear (car(gimp-image-get-layer-by-name 1  "background copy" )))
 (gimp-item-set-visible (car(gimp-image-get-layer-by-name 1  "background" )) 0)
 (gimp-file-save 0 1 (car(gimp-image-get-layer-by-name 1  "background copy" )) "Style_A_1.png" "Style_A_1.png")
 (gimp-item-delete (car(gimp-image-get-layer-by-name 1  "background copy" ))))

Error: Procedure execution of gimp-item-delete failed 

I have tried deleting it by the id alone in the console ie (gimp-item-delete  13589 )
with the same results.

Any examples or guidance would be appreciated.

best regards
Dalton


RE: Delete Layer? - Ofnuts - 11-29-2022

To remove a layer use (gimp-image-remove-layer image layer) (this releases the memory).

IMHO you script would be more robust if you start by setting a variable to the layer returned by gimp-layer-new-from-drawable and then use this variable instead of calling gimp-image-get-layer-by-name, because you script will fail if there is already a "background copy". Your background layer is also the last of the layers is the list, so you don't need its name...


RE: Delete Layer? - DaltonCalford - 11-30-2022

(11-29-2022, 06:27 PM)Ofnuts Wrote: To remove a layer use (gimp-image-remove-layer image layer) (this releases the memory).

IMHO you script would be more robust if you start by setting a variable to the layer returned by  gimp-layer-new-from-drawable and then use this variable instead of calling  gimp-image-get-layer-by-name, because you script will fail if there is already a "background copy". Your background layer is also the last of the layers is the list, so you don't need its name...

Hi Ofnuts,

Interesting, the Script-Fu Procedure Browser when searching for gimp-layer-delete specifies to use gimp-item-delete and does not mention "gimp-image-remove-layer" 
That was the key to success.

I use variables in my actual script, but wanted to provide a quick code example that would run in the console without lots of variables.
I just used background as a layer name as a safe example name vs the actual layer names.

I like what I can do with script-fu, but, the documentation leaves a lot to be desired.

Thanks for your help.