GIMP Chat
http://gimpchat.com/

Script writer newbie
http://gimpchat.com/viewtopic.php?f=9&t=18003
Page 1 of 1

Author:  Pocholo [ Sat Feb 08, 2020 2:39 pm ]
Post subject:  Script writer newbie

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:

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

Author:  ofnuts [ Sat Feb 08, 2020 7:16 pm ]
Post subject:  Re: Script writer newbie

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.

Author:  MareroQ [ Sat Feb 08, 2020 11:49 pm ]
Post subject:  Re: Script writer newbie

Hi Pocholo.

Did Ofnuts' comments help?
If not - see for example:
(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

Author:  Pocholo [ Sun Feb 09, 2020 1:36 am ]
Post subject:  Re: Script writer newbie

@ 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

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