Gimp-Forum.net
Editing max and min .scm - Printable Version

+- Gimp-Forum.net (https://www.gimp-forum.net)
+-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP)
+--- Forum: Extending the GIMP (https://www.gimp-forum.net/Forum-Extending-the-GIMP)
+--- Thread: Editing max and min .scm (/Thread-Editing-max-and-min-scm)



Editing max and min .scm - Krikor - 04-14-2023

Hey guys,

I would like a small favor.

I would like to change a script so that it allows me to enter 0 (zero) as a minimum value and 2000 as a maximum value.

The script in its original form only allows me to enter values from 1 to 500.

I thought of manually editing the values in the .scm file, changing the values 1 to zero and 500 to 2000 respectively, but when in doubt I decided to ask for help.

Below the .scm
Code:
; Luigi Chiesa 2008.  No copyright.  Public Domain.
; Add a grid of guides
; 2012 R. Antonishen - modified to allow creating a grid of guides based of the active layer rather than the image canvas

(define (script-fu-grid-guides InImage InSource InHGrid InVGrid InMode InBorder)
 (gimp-image-undo-group-start InImage)
 (let* (
       (width (if (= InSource 0) (car (gimp-image-width InImage)) (car (gimp-drawable-width (car (gimp-image-get-active-drawable InImage))))))
         (height (if (= InSource 0) (car (gimp-image-height InImage)) (car (gimp-drawable-height (car (gimp-image-get-active-drawable InImage))))))
       (divH (if (= InMode 0) (/ width InHGrid) InHGrid))
       (divV (if (= InMode 0) (/ height InVGrid) InVGrid))
       (InHGrid (if (= InMode 0) InHGrid (/ width InHGrid)))
       (InVGrid (if (= InMode 0) InVGrid (/ height InVGrid)))
       (hcount 1)
       (vcount 1)
       (xoff (if (= InSource 0) 0 (car (gimp-drawable-offsets (car (gimp-image-get-active-drawable InImage))))))
       (yoff (if (= InSource 0) 0 (cadr (gimp-drawable-offsets (car (gimp-image-get-active-drawable InImage))))))
       )
       
   (if (= InBorder TRUE)
     (begin
       (if (and (>= yoff 0) (<= yoff (car (gimp-image-height InImage))))(gimp-image-add-hguide InImage yoff))
       (if (and (>= (+ yoff height) 0) (<= (+ yoff height) (car (gimp-image-height InImage)))) (gimp-image-add-hguide InImage (+ yoff height)))
       (if (and (>= xoff 0) (<= xoff (car (gimp-image-width InImage)))) (gimp-image-add-vguide InImage xoff))
       (if (and (>= (+ xoff width) 0) (<= (+ xoff width) (car (gimp-image-width InImage)))) (gimp-image-add-vguide InImage (+ xoff width)))
     )
   )
    
   (while (< hcount InVGrid)
     (if (and (>= (+ yoff (* divV hcount)) 0) (<= (+ yoff (* divV hcount)) (car (gimp-image-height InImage)))) (gimp-image-add-hguide InImage (+ yoff (* divV hcount))))
     (set! hcount (+ hcount 1))
   )

   (while (< vcount InHGrid)
     (if (and (>= (+ xoff (* divH vcount)) 0) (<= (+ xoff (* divH vcount)) (car (gimp-image-width InImage)))) (gimp-image-add-vguide InImage (+ xoff (* divH vcount))))
     (set! vcount (+ vcount 1))
   )

    (gimp-image-undo-group-end InImage)
 (gimp-displays-flush)
 )
)

(script-fu-register
 "script-fu-grid-guides"
 "<Image>/Image/Guides/Grid"
 "Add a grid of guides by specifying either the number of guides or the guide spacing"
 "Luigi Chiesa and Rob Antonishen"
 "Public Domain"
 "November 2009"
 "*"
   SF-IMAGE      "Image"   0
    SF-OPTION       "Based on" '("Image Canvas" "Active Layer")    
    SF-ADJUSTMENT    "Horizontal"    '(2 1 500 1 10 0 1)
    SF-ADJUSTMENT    "Vertical"    '(2 1 500 1 10 0 1)
    SF-OPTION       "Mode" '("Number of Divisions" "Spacing of Guides (px)")    
   SF-TOGGLE "Border guides?" FALSE
)

Thanks in advance!


RE: Editing max and min .scm - PixLab - 04-14-2023

(04-14-2023, 01:57 PM)Krikor Wrote: SF-ADJUSTMENT "Horizontal" '(2 1 500 1 10 0 1)
SF-ADJUSTMENT "Vertical" '(2 1 500 1 10 0 1)

I did found this

Code:
SF-ADJUSTMENT "label" '(value, lower, upper, step_inc, page_inc, digits, type)

here > https://www.gimpusers.com/forums/gimp-user/2056-script-fu-documentation-of-sf-adjustment-and-others

[attachment=9699]

Thus I would try SF-ADJUSTMENT "Horizontal" '(2 0 2000 1 10 0 1) and if it's not working... yes I'm stupid enough to try things by my own, and there is a lot of things like "if (blabla = 0)" which will bother me in the code if my try doesn't work, thus I'll come back here for help if my try does not work > but you should know that I don't know anything about script Wink

Hope it helps


RE: Editing max and min .scm - Krikor - 04-14-2023

(04-14-2023, 02:30 PM)PixLab Wrote:
(04-14-2023, 01:57 PM)Krikor Wrote: SF-ADJUSTMENT "Horizontal" '(2 1 500 1 10 0 1)
SF-ADJUSTMENT "Vertical" '(2 1 500 1 10 0 1)

I did found this

Code:
SF-ADJUSTMENT "label" '(value, lower, upper, step_inc, page_inc, digits, type)

here > https://www.gimpusers.com/forums/gimp-user/2056-script-fu-documentation-of-sf-adjustment-and-others



Thus I would try SF-ADJUSTMENT "Horizontal" '(2 0 2000 1 10 0 1) and if it's not working... yes I'm stupid enough to try things by my own, and there is a lot of things like "if (blabla = 0)" which will bother me in the code if my try doesn't work, thus I'll come back here for help if my try does not work > but you should know that I don't know anything about script Wink

Hope it helps

Intuitively that's exactly what I suppose!
But I had the same doubt about the last three (3) digits (10 0 1 ), so I preferred to ask for help!

More confident now I will test the changes then.

PixLab, thank you very much for your quick and efficient help!


PS: 

After changing the code as below, the script accepts the values 0 (zero) and 2000 as input.

However, it generates an error and does not produce tab separation.
________________________________________________________

SF-ADJUSTMENT "Horizontal" '(2 0 2000 1 10 0 1)

SF-ADJUSTMENT "Vertical" '(2 0 2000 1 10 0 1)

________________________________________________________

  Grid Warning
Error while executing script-fu-grid-guides:

Error: /: division by zero 


  GIMP Warning
Plug-in 'Grid' left image undo in inconsistent state, closing open undo groups.

Even though it was impossible to enter zero (0) as the minimum value, being able to increase the maximum value was already a huge improvement in the script for my use!

I manage to work around the situation as follows:
For a 5000W x 1000H (px) image, where I want a guide every 1000 px:

Mode - Spacing of Guides (px):
Horizontal = 1000
Vertical = 1000 **

** Note: The interesting thing here is that no vertical guide is generated!

Number of Divisions Mode:
Horizontal = 5
Vertical = 1


RE: Editing max and min .scm - programmer_ceds - 04-14-2023

(04-14-2023, 03:08 PM)Krikor Wrote:
(04-14-2023, 02:30 PM)PixLab Wrote:
(04-14-2023, 01:57 PM)Krikor Wrote: SF-ADJUSTMENT "Horizontal" '(2 1 500 1 10 0 1)
SF-ADJUSTMENT "Vertical" '(2 1 500 1 10 0 1)

I did found this

Code:
SF-ADJUSTMENT "label" '(value, lower, upper, step_inc, page_inc, digits, type)

here > https://www.gimpusers.com/forums/gimp-user/2056-script-fu-documentation-of-sf-adjustment-and-others



Thus I would try SF-ADJUSTMENT "Horizontal" '(2 0 2000 1 10 0 1) and if it's not working... yes I'm stupid enough to try things by my own, and there is a lot of things like "if (blabla = 0)" which will bother me in the code if my try doesn't work, thus I'll come back here for help if my try does not work > but you should know that I don't know anything about script Wink

Hope it helps

Intuitively that's exactly what I suppose!
But I had the same doubt about the last three (3) digits (10 0 1 ), so I preferred to ask for help!

More confident now I will test the changes then.

PixLab, thank you very much for your quick and efficient help!


PS: 

After changing the code as below, the script accepts the values 0 (zero) and 2000 as input.

However, it generates an error and does not produce tab separation.
________________________________________________________

SF-ADJUSTMENT "Horizontal" '(2 0 2000 1 10 0 1)

SF-ADJUSTMENT "Vertical" '(2 0 2000 1 10 0 1)

________________________________________________________

  Grid Warning
Error while executing script-fu-grid-guides:

Error: /: division by zero 


  GIMP Warning
Plug-in 'Grid' left image undo in inconsistent state, closing open undo groups.

Even though it was impossible to enter zero (0) as the minimum value, being able to increase the maximum value was already a huge improvement in the script for my use!

I manage to work around the situation as follows:
For a 5000W x 1000H (px) image, where I want a guide every 1000 px:

Mode - Spacing of Guides (px):
Horizontal = 1000
Vertical = 1000 **

** Note: The interesting thing here is that no vertical guide is generated!

Number of Divisions Mode:
Horizontal = 5
Vertical = 1
Surely the lower limit should be 1 - apart from a value of 0 causing the divide by zero error it makes no sense to have a guide spacing of 0.


RE: Editing max and min .scm - Ofnuts - 04-14-2023

(04-14-2023, 04:07 PM)programmer_ceds Wrote: Surely the lower limit should be 1 - apart from a value of 0 causing the divide by zero error it makes no sense to have a guide spacing of 0.

Indeed... I have some respect for one of the authors(*) and some thought has been put in this script in its original form. Changing things at random without understanding how it works isn't going to be pretty.

(*) And that's fairly rare coming from me Angel


RE: Editing max and min .scm - PixLab - 04-15-2023

(04-14-2023, 04:07 PM)programmer_ceds Wrote: Surely the lower limit should be 1 - apart from a value of 0 causing the divide by zero error it makes no sense to have a guide spacing of 0.

Oh yes, you're right, this cannot be 0/zero spaced

(04-14-2023, 03:08 PM)Krikor Wrote: I manage to work around the situation as follows:
For a 5000W x 1000H (px) image, where I want a guide every 1000 px:

Mode - Spacing of Guides (px):
Horizontal = 1000
Vertical = 1000 **

** Note: The interesting thing here is that no vertical guide is generated!

Because your image has 1000px in height... use "Border guides" Wink