You are here

How do I return a value from a GIMP (scheme) script?

Maybe this is already answered in here, but a search for "return" didn't uncover it. How do I return a value from a GIMP (scheme) script? I know there is a simple way to do it, and I remember seeing it in a script once, but I don't remember which one, so I don't know how to do it.

This is partial code for a script. I want to be able to return all three GIMP release/version/minor version values. I already have code that does what I want, except I don't know how to return the values.

How do I return values from a script that will work in 2.6.x and higher (I want to be backwards compatible to 2.6.x)? Sorry if this is a stupid question. Thanks for any help.

(define (getRelVerGIMP
; no input arguments
)
(let*(
; all variables will be defined here, but not all shown...
(relVerGimp ()) ; Full GIMP version i.e. 2.6.12, 2.7.5, or 2.8.0
(numRelGimp ()) ; numeric value of Release (i.e. 2)
(numVerGimp ()) ; numeric value of Version (i.e. 6)
(numMinorRelGimp ()) ; numeric value of Minor Release (i.e. 12)
) ; end of variable definitions

; Save the current release/version for GIMP into a string, etc. (not all code shown)
(set! relVerGimp (car(gimp-version)))
; Parse the string into its character components, then convert to numeric.

) ; end of let

; Return values
(numVerGimp)

; Note: I want to be able to return numRelGimp, numVerGimp, numMinorRelGimp

) ; end define getRelVerGIMP

I figured it out. This worked for me:

I added variable:

(listReturnValues ()) ; return values for function

Then I did this at the end:

; Return values
(set! listReturnValues (list numRelGimp numVerGimp numMinorRelGimp))

) ; end of let

) ; end define getRelVerGIMP

Your approach is basically correct, I would just point out that it is not absolutely necessary to create a variable and assign it with 'set!'. The last expression in a 'let' is the "return value" of the let, so if your last line were:

(list numRelGimp numVerGimp numMinorRelGimp)

then the result would be the same.

Also, it should probably be mentioned that while scripts that are registered with the PDB (using 'gimp-script-fu-register) can return values such as your list, but such return values are only available to other Script-fus. Plug-ins written in Python or C will not receive any return values when a script is invoked through the PDB (the only value returned from a script through the PDB is success or fail status).

For example, if you wrote a script that decomposed the RGB channels to separate layers, and returned a list of those three layers, then other scripts calling yours would have access to that list of layers, however, a Python plug-in calling your script would not.

Thanks for the information. I'm still new to writing scripts. I had done some Internet searches, and finally figured out what I needed to do, and coded it that way. But I didn't see anything telling me about what you just said. I see there is more for me to learn.

Subscribe to Comments for "How do I return a value from a GIMP (scheme) script?"