Reputation: 121
Seems like a simple thing but I haven't found an answer.
Custom script. How do you return a variable?
Specifically, I want to return copiedLayer.
(define (script-copy-first-layer inImg)
(let*
(
(layers (cadr (gimp-image-get-layers inImg) ) )
(numLayers (car (gimp-image-get-layers inImg) ) )
(layer (aref layers 0))
(copiedLayer (car (gimp-layer-copy layer TRUE)))
)
(gimp-image-add-layer inImg copiedLayer 0)
(gimp-layer-set-visible copiedLayer TRUE)
(gimp-layer-set-lock-alpha copiedLayer TRUE)
(gimp-layer-add-alpha copiedLayer)
)
)
(script-fu-register
"script-copy-first-layer"
"<Image>/Image/Copy First Layer"
"Copy First Layer"
"Black Orchid Studios"
"Black Orchid Studios"
"July 2017"
"RGB*, GRAY*"
SF-IMAGE "Image" 0
)
Upvotes: 1
Views: 545
Reputation: 2016
ScriptFu scripts declare and define PDB procedures in the GIMP Procedural Database.
But you can't declare a return type. Notice that 'script-fu-register' is declaring. Unlike in PyGimp, there is no clause for declaring return values. All PDB procedures (aka plugins) declared in ScriptFu return void.
Considered as just Lisp, scripts DO return the value of the last evaluated expression. But it doesn't pass through the PDB machinery. Within the same program text, you can call the defined function 'script-copy-first-layer' and receive a value, but you can't call the corresponding PDB procedure from another script and receive a value.
Strange but true. There is no good reason why it is so.
Upvotes: 0
Reputation: 181
Simply add copiedLayer
to the end of the let
statement.
I believe this is what you need:
(define (script-copy-first-layer inImg)
(let*
(
(layers (cadr (gimp-image-get-layers inImg) ) )
(numLayers (car (gimp-image-get-layers inImg) ) )
(layer (aref layers 0))
(copiedLayer (car (gimp-layer-copy layer TRUE)))
)
(gimp-image-add-layer inImg copiedLayer 0)
(gimp-layer-set-visible copiedLayer TRUE)
(gimp-layer-set-lock-alpha copiedLayer TRUE)
(gimp-layer-add-alpha copiedLayer)
copiedLayer
)
)
(script-fu-register
"script-copy-first-layer"
"<Image>/Image/Copy First Layer"
"Copy First Layer"
"Black Orchid Studios"
"Black Orchid Studios"
"July 2017"
"RGB*, GRAY*"
SF-IMAGE "Image" 0
)
Upvotes: 3