Search code examples
gimpscript-fugimpfu

script-fu invalid number of arguments


I want to create an image like notebooke paper, and I thought it is easy if the section of drawing lines is automated.

In order to make it, I decided to use gimp's function named 'gimp-rect-select' and specify the small height value.

I google-searched and wrote a scheme file, but when I ran it from gimp's Script-Fu menu, gimp showed me the message as below.

Error while executing FU01-multi-rect-select:

Error: ( : 1) 

Invalid number of arguments for gimp-rect-select 
(expected 8 but received 9) 

I would like you to see my first script-fu and point out where something wrong is involved.

To me, my custom function is defined so that it has 8 parameters, not 9. The folloing is my code

    (define (FU01-multi-rect-select 
    image 
    drawable 
    x1 
    y1 
    w 
    h 
    p-offset 
    p-repeat
    )
    ;definition of variables
    (let* 
      (
        (X nil) 
        (Y nil) 
        (width nil) 
        (height nil) 
        (offset nil) 
        (repeat nil) 
        ;are they below necessary?
        (theLayer nil)
        (theImage nil)
      )
      ;(gimp-context-push ) 
      (gimp-image-undo-group-start image)
        
      ;(set! X (string->number x1))
      ;(set! Y (string->number y1))
      ;(set! width (string->number w))
      ;(set! height (string->number h))
      ;(set! offset (string->number p-offset))
      ;(set! repeat (string->number p-repeat))
        
      (set! X x1)
      (set! Y y1)
      (set! width w)
      (set! height h)
      (set! offset p-offset)
      (set! repeat p-repeat)

      (gimp-image-set-active-layer image drawable)
            
      (set! theLayer
        (car (gimp-image-get-active-layer image) )
      )
        
      ; select rectangle and after that, 
      ; add it to current selection
      ; multiple times that is specified with 'repeat'
      (while (> repeat 0)
        (gimp-rect-select image X Y width height 
                             CHANNEL-OP-ADD FALSE 0 0)
        (set! Y (+ Y height offset))
        (set! repeat (- repeat 1))
      )
        
      (gimp-image-undo-group-end image)
    ) ; end of let sentences

  )

    (script-fu-register "FU01-multi-rect-select" 
    "<Image>/Script-Fu/Select/multi rect select" 
    "add a rect selection to current selection multiple times\
    each time a rect is selected it is moved\
     in y axis by the value of offset" 
    "Masaaki Fujioka" 
    "copy right 2014 Masaaki Fujioka" 
    "August 3 2014" 
    "*" 
    SF-IMAGE    "SF-IMAGE"      0  
    SF-DRAWABLE "SF-DRAWABLE"   0   
    SF-VALUE    "start x"       "0" 
    SF-VALUE    "start y"       "0" 
    SF-VALUE    "width"         "0" 
    SF-VALUE    "height"        "0" 
    SF-VALUE    "offset"        "0" 
    SF-VALUE    "repeat"        "0" 

    )

Solution

  • Just like the error message says, you have one extra parameter to the gimp-rect-select call - if you check the specs for the call on the procedure browser, after the "mode" parameter there should be one boolean to tell whether you want to use feathering, and another number to tell the feathering amount. You are passing two integers instead of just one number needed.

    Also, pay attention that this call is marked as "deprecated" - which means that although it still works in gimp-2.8, for a series of reason, you should be calling gimp-image-select-rectangle instead of this. (note that the parameters for that call differ).