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

Script writer newbie

Sat Feb 08, 2020 2:39 pm

Hi everyone! I'm trying to learn how to write scripts and I'm going through the basics. I'm trying to create a simple "Slider" dialog that will create a New image. But when I'm trying to run it, it's giving me an error. Can any experience coder here explain what am I doing wrong?

"Error while executing script-fu-new-layer-white:
Error: eval: unbound variable: image"

This is what the script looks like:

Code:
(define (script-fu-new-layer-white)
   (gimp-image-new 400 400 GRAY)
   (gimp-layer-new image 400 400 GRAY-IMAGE "New" 100 LAYER-MODE-NORMAL)
   (gimp-image-insert-layer image layer 0 0)
   (gimp-drawable-fill layer FILL-WHITE)
   (gimp-display-new image)
   
)   
   
(script-fu-register   
   "script-fu-new-layer-white"
   "<Image>/Files/Create/New layer"
   "Generates a New layer"
   "Pocholo"
   "Pocholo"
   "Feb 2020"
   ""
   SF-ADJUSTMENT "Layer Size (px)" '(400 1200 1 10 0 SF-SLIDER)

Re: Script writer newbie

Sat Feb 08, 2020 7:16 pm

Pocholo wrote:I'm trying to learn how to write scripts


So you should really use Python instead. Much easier to learn.

This said, looking at your code, gimp-image-new and gimp-layer-new both return the id of the created image layer, so you have to keep these somewhere to be able to reuse them in the following function calls.

Re: Script writer newbie

Sat Feb 08, 2020 11:49 pm

Hi Pocholo.

Did Ofnuts' comments help?
If not - see for example:
Code:
(define (script-fu-new-layer-white size)

   (let*(
       (image (car (gimp-image-new size size GRAY)))
       (test (car (gimp-layer-new image size size GRAY-IMAGE "New" 100 LAYER-MODE-NORMAL)))
         )
   (gimp-image-insert-layer image test 0 0)
   (gimp-drawable-fill test FILL-WHITE)
   (gimp-display-new image)
    )
)
(script-fu-register
   "script-fu-new-layer-white"
   "<Image>/File/Create/New layer..."
   "Generates a New layer"
   "Pocholo"
   "Pocholo"
   "Feb 2020"
   ""
   SF-ADJUSTMENT "Layer Size (px)" '(400 1 1200 1 10 0 SF-SLIDER)


And three more comments:
1. If you enter the selection parameter (SF-ADJUSTMENT) must be defined.
2. SF-ADJUSTMENT "Layer Size (px)" '(400 1200 1 10 0 SF-SLIDER) requires 7 arguments (not 6)
3. Location on the menu is probably:
"<Image>/File/Create/New layer..." (not Files)

Python basics are probably easier to learn (and only this has a future...)
Good luck in Your studies :jumpclap

Re: Script writer newbie

Sun Feb 09, 2020 1:36 am

@ ofnuts: Thank you so much for the advise! I will give it a try at python scripting.

@MareroQ: Thank you for the fixing!
You guys are awesome! :jumpclap :tyspin
Post a reply