03-08-2025, 10:14 AM
(03-07-2025, 10:53 AM)teapot Wrote: Your cond statement doesn't make much sense but seeing as that's what you are doing:
The function = does not take #t and #f. It can take numbers. Gimp provided TRUE and FALSE which are 1 and 0 so if they are still in gimp 3 you could use them in your cond statement instead of the #t.
According to this link
https://developer.gimp.org/resource/scri...ng-boolean
I was incorrect in my conditional code. In v3 dialect, the correct code differs from that in v2. Why I choose to deal with v3 dialect? The Gimp developers wrote: You should plan on porting existing scripts to the v3 dialect, since eventually ScriptFu may obolete the v2 dialect. This is a citation from the link above. Hence, for me, it is easier to rewrite a few of my scripts now, when I have some time to deal with it.
It was not trivial for me, having little programming background, to find a solution. However, finally I rewrite the script into v3 dialect of ScriptFu. It is much shorter since I've decided to remove some code. The script aimed to add user defined text with user specified x and y offsets with relation to the upper left corner of the currently selected layer. Here is the code:
Code:
#!/usr/bin/env gimp-script-fu-interpreter-3.0
(define (script-fu-add-labels image drawables user-text font font-size font-color x y)
(script-fu-use-v3)
(let* ((current-layer (vector-ref drawables 0))
(off-x (car (gimp-drawable-get-offsets current-layer)))
(off-y (cadr (gimp-drawable-get-offsets current-layer)))
(text-layer)
(text-layer-position-x (+ off-x x))
(text-layer-position-y (+ off-y y))
(text-foreground-color-old)
(layer-type 0))
(gimp-image-undo-group-start image)
(cond
((gimp-item-id-is-channel current-layer) (set! layer-type 1))
((gimp-item-id-is-group-layer current-layer) (set! layer-type 1))
((gimp-item-id-is-layer-mask current-layer) (set! layer-type 1))
((gimp-item-id-is-path current-layer) (set! layer-type 1))
((gimp-item-id-is-text-layer current-layer) (set! layer-type 1))
((gimp-item-id-is-selection current-layer) (set! layer-type 1))
)
(if (< 1 layer-type)
(begin (gimp-message "Cannot add the label to the selected layer"))
(begin (set! text-layer (gimp-text-font image -1 text-layer-position-x
text-layer-position-y user-text 0 #t
font-size font))
(gimp-text-layer-set-color text-layer font-color)
(gimp-item-set-lock-position text-layer #t)))
(gimp-displays-flush)
(gimp-image-undo-group-end image)))
(script-fu-register-filter "script-fu-add-labels"
_"Add label..."
_"Adds a label to currently selected layer"
"alvk"
""
""
"*"
SF-ONE-DRAWABLE
SF-STRING _"Label" "A"
SF-FONT _"Font" "Arial Bold"
SF-ADJUSTMENT _"Font size" (list 50 5 100 1 10 0 1)
SF-COLOR _"Font color" (list 0 0 0)
SF-ADJUSTMENT _"Offset X" (list 6 0 500 1 10 0 1)
SF-ADJUSTMENT _"Offset Y" (list 6 0 500 1 10 0 1)
)
(script-fu-menu-register "script-fu-add-labels"
"<Image>/Figures")
