11-05-2022, 12:19 AM
Hello everyone!
I'm using gimp to make figures for my scientific papers. Often I need to place a guide in a certain position relative to a selected layer. I'm trying to write a pretty simple script, that do the job. However, I have a problem with it. I want to have a checkbox, with indicates whether the guide should be placed within the selected layer or not. But it doesn't work. Every time, the script return negative value for guide position. If I have a multilayer image, this means that the guide is placed outside the active layer, regardless of the state of the checkbox. If I have a single layer image, I get an error, that the guide is outside the image. Could anyone help me to solve this problem? The full script is below. Thank you!
I'm using gimp to make figures for my scientific papers. Often I need to place a guide in a certain position relative to a selected layer. I'm trying to write a pretty simple script, that do the job. However, I have a problem with it. I want to have a checkbox, with indicates whether the guide should be placed within the selected layer or not. But it doesn't work. Every time, the script return negative value for guide position. If I have a multilayer image, this means that the guide is placed outside the active layer, regardless of the state of the checkbox. If I have a single layer image, I get an error, that the guide is outside the image. Could anyone help me to solve this problem? The full script is below. Thank you!
Code:
(define (script-fu-custom-guide image
drawable
orientation
position
in_toggle)
(let* (
(lwidth (car (gimp-drawable-get-width image)))
(lheight (car (gimp-drawable-get-height image)))
(offx (car (gimp-drawable-get-offsets drawable)))
(offy (cadr (gimp-drawable-get-offsets drawable)))
(if (= in_toggle TRUE) (position (* -1 position)))
(guide_position
(cond ((= orientation 0) (- offx position)) ; guide on left
((= orientation 1) (+ offx lwidth position)) ; guide on right
((= orientation 2) (- offy position)) ; guide on top
((= orientation 3) (+ offy lheight position)) ; guide on bottom
)
)
)
(if (< 1 orientation)
(gimp-image-add-hguide image guide_position)
)
(if (> 2 orientation)
(gimp-image-add-vguide image guide_position)
)
(gimp-displays-flush)
)
)
(script-fu-register "script-fu-custom-guide"
_"_Custom guide"
_"Adds a vertical or horizontal guide to the image"
""
""
""
"*"
SF-IMAGE "Input image" 0
SF-DRAWABLE "Input drawable" 0
SF-OPTION _"_Orientation" '(_"Left" _"Right" _"Top" _"Bottom")
SF-ADJUSTMENT _"_Position" (list 20 0 MAX-IMAGE-SIZE 1 10 0 1)
SF-TOGGLE _"Within a layer?" FALSE
)
(script-fu-menu-register "script-fu-custom-guide"
"<Image>/Figures")