It is currently Sat Jun 22, 2024 8:51 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Script-fu
PostPosted: Sat Sep 17, 2022 8:44 am  (#1) 
Offline
New Member

Joined: Sep 17, 2022
Posts: 3
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.


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: Script-fu
PostPosted: Sat Sep 17, 2022 9:46 am  (#2) 
Offline
Script Coder
User avatar

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

_________________
Image


Top
 Post subject: Re: Script-fu
PostPosted: Sat Sep 17, 2022 11:41 am  (#3) 
Offline
New Member

Joined: Sep 17, 2022
Posts: 3
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.


Top
 Post subject: Re: Script-fu
PostPosted: Sat Sep 17, 2022 2:22 pm  (#4) 
Offline
Script Coder
User avatar

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

_________________
Image


Top
 Post subject: Re: Script-fu
PostPosted: Sat Sep 17, 2022 3:17 pm  (#5) 
Offline
New Member

Joined: Sep 17, 2022
Posts: 3
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
)


Top
 Post subject: Re: Script-fu
PostPosted: Sat Sep 17, 2022 4:07 pm  (#6) 
Offline
GimpChat Member

Joined: Jul 28, 2018
Posts: 1196
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

_________________
https://www.deviantart.com/pocholo17
Image
Top
 Post subject: Re: Script-fu
PostPosted: Sat Sep 17, 2022 8:20 pm  (#7) 
Offline
GimpChat Member
User avatar

Joined: May 16, 2010
Posts: 14709
Location: USA
monsoonami on YouTube has several great tutorials as well.

_________________
Image
Edmund Burke nailed it when he said, "The only thing necessary for the triumph of evil is for good men to do nothing."


Top
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Attachment(s) Looking for Script Coder to make Script of my VHS effect

2

No new posts Attachment(s) A liitle Start Help with a Script-Fu Script

3

No new posts Attachment(s) Cannot run test script-fu script via console

7

No new posts Attachment(s) Rotate Hue Script

74

No new posts GLOSSY SCRIPT

2



* Login  



Powered by phpBB3 © phpBB Group