GIMP Chat
http://gimpchat.com/

Script-fu
http://gimpchat.com/viewtopic.php?f=8&t=20123
Page 1 of 1

Author:  Bongobat [ Sat Sep 17, 2022 8:44 am ]
Post subject:  Script-fu

GIMP Version: 2.10.30
Operating System: Windows
OS Version: 10
GIMP Experience: New User

List any ERROR messages you received:
Error while executing script-fu-mockup:

Error: eval: unbound variable: script-fu-mockup




Hi I am new to GIMP and I'm trying to use script-fu to make a simple script that takes the active layer and adjusts the perspective to fit some known coordinates but it's failing and I can't figure out why and was hoping someone could help. Here is the code
(define (mockup x)
(gimp-item-transform-perspective x 272 154 450 217 275 666 448 618)
)

(script-fu-register
"script-fu-mockup"
"<Image>/Tools/Transform Tools/Mockup"
"Image mockup placement tool."
"GQ"
"GQ"
"September 15"
"RGB*, Gray*"
SF-DRAWABLE "x" 0
)


I think its got something to do with passing the layer id to (gimp-item-transform-perspective) I discovered the function called CAR (Contents of Address Register) and tried applying it to a variable after getting the id with (gimp-image-get-active-layer 1) this works in the console but wont work in the registered code.
(gimp-item-transform-perspective (car(gimp-image-get-active-layer 1)) 272 154 450 217 275 666 448 618)


Any hints on how i could get it to work in a registered script would be appreciated.

Author:  ofnuts [ Sat Sep 17, 2022 9:46 am ]
Post subject:  Re: Script-fu

When you register a script, if the first two arguments of the script are in that order, and image and a drawable (so SF-IMAGE and SF-DRAWABLE in script-fu), they will be set to the current image and the image active drawable when script is called, and this is the normal way to register a script.

When you do so

* there is no need to call "gimp-image-get-active-layer".
* even if you do your get a proper image ID to use with it ("1" is the ID of the first image you load per Gimp session, all other images will have another ID).
* and this gives you a script that works on any image loaded in Gimp...

Author:  Bongobat [ Sat Sep 17, 2022 11:41 am ]
Post subject:  Re: Script-fu

Thank you for responding but I am still confused.
I was following a youtube video called "GIMP Script-Fu 2: Write Your First Script" ( forum wont let me post link)

Quote:
When you register a script, if the first two arguments of the script are in that order, and image and a drawable (so SF-IMAGE and SF-DRAWABLE in script-fu), they will be set to the current image and the image active drawable when script is called, and this is the normal way to register a script.


That is what I thought and why I didn't use "gimp-image-get-active-layer" in the registered script. I was trying to get it to trouble shoot and get it to work in the console and the only thing that works there is
(gimp-item-transform-perspective (car(gimp-image-get-active-layer 1)) 272 154 450 217 275 666 448 618)


The console wouldn't work either until I called (car) on the function for the active layer.

I rewrote this script but it still is failing with Execution error for 'Mockup':
Error: eval: unbound variable: script-fu-mockup

(define (mockup image layer)
(gimp-item-transform-perspective layer 272 154 450 217 275 666 448 618)
)

(script-fu-register
"script-fu-mockup"
"<Image>/Tools/Transform Tools/Mockup"
"Image mockup placement tool."
"GQ"
"GQ"
"September 15"
"RGB*, Gray*"
SF-IMAGE "image" 0
SF-DRAWABLE "layer" 0
)


If you could point out in this code where I am going wrong it would be greatly appreciated.

Author:  ofnuts [ Sat Sep 17, 2022 2:22 pm ]
Post subject:  Re: Script-fu

Bongobat wrote:
Thank you for responding but I am still confused.
I was following a youtube video called "GIMP Script-Fu 2: Write Your First Script" ( forum wont let me post link)

Quote:
When you register a script, if the first two arguments of the script are in that order, and image and a drawable (so SF-IMAGE and SF-DRAWABLE in script-fu), they will be set to the current image and the image active drawable when script is called, and this is the normal way to register a script.


That is what I thought and why I didn't use "gimp-image-get-active-layer" in the registered script. I was trying to get it to trouble shoot and get it to work in the console and the only thing that works there is
(gimp-item-transform-perspective (car(gimp-image-get-active-layer 1)) 272 154 450 217 275 666 448 618)


The console wouldn't work either until I called (car) on the function for the active layer.

I rewrote this script but it still is failing with Execution error for 'Mockup':
Error: eval: unbound variable: script-fu-mockup

(define (mockup image layer)
(gimp-item-transform-perspective layer 272 154 450 217 275 666 448 618)
)

(script-fu-register
"script-fu-mockup"
"<Image>/Tools/Transform Tools/Mockup"
"Image mockup placement tool."
"GQ"
"GQ"
"September 15"
"RGB*, Gray*"
SF-IMAGE "image" 0
SF-DRAWABLE "layer" 0
)


If you could point out in this code where I am going wrong it would be greatly appreciated.


Not a Scheme expert, I write my script in Python (but they work along the same principles). However I note that in the scripts that are installed with Gimp, the first arg to "script-fu-register" ("script-fu-mockup" in your case) is also the name of the function that implements the script, which is not true in your case ("mockup" != "script-fu-mockup").

Author:  Bongobat [ Sat Sep 17, 2022 3:17 pm ]
Post subject:  Re: Script-fu

Wow Thank you so much! I didn't realized you had to name the function a certain way. Now that you pointed it out it makes sense. Here is the working code with the name correct and I added (gimp-displays-flush):

(define (script-fu-mockup image layer)
(gimp-item-transform-perspective layer 272 154 450 217 275 666 448 618)
(gimp-displays-flush)
)

(script-fu-register
"script-fu-mockup"
"<Image>/Tools/Transform Tools/Mockup"
"Image mockup placement tool."
"GQ"
"GQ"
"September 15"
"RGB*, Gray*"
SF-IMAGE "image" 0
SF-DRAWABLE "layer" 0
)

Author:  Pocholo [ Sat Sep 17, 2022 4:07 pm ]
Post subject:  Re: Script-fu

Hi Bongobat. I started learning coding with "Scheme" but like ofnuts stated Python is so much easier and cleaner. I encourage you to learn Python. But if you has chosen to learn Scheme, one of our own member "Fencepost" has written a 3 parts scheming tutorials that is wonderful for new users who want to learn how to code. Download the folders with five PDF tutorials.

Attachments:
GIMP Scheme tutorial.zip [1.24 MiB]
Downloaded 31 times

Author:  Rod [ Sat Sep 17, 2022 8:20 pm ]
Post subject:  Re: Script-fu

monsoonami on YouTube has several great tutorials as well.

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