Sweeney wrote:
Thanks for the reply, not sure how to use the console, it only seems to have a one line text box.
I'm used to Maya and the script window in there.
Like how do you test larger bits of code, with several variables?
Enter your code into a separate text editor (preferably one that at least highlights matching parentheses), and then copy-n-paste the code into GIMP's Script-fu console as you debug it.
You can have multiple lines but your pasted code needs to be complete Scheme expressions. For example, if you paste in "(define x 10", leaving off the trailing parenthesis, the console will not wait for you to enter in the parenthesis; it will merely print out that an <EOF> was encountered and 'x' will not be defined.
When using a lot of variable bindings that appear in your code in a 'let' block, these will typically need to be converted to define statements if you wish to interact with your code step-by-step. For example, consider the following bit of code:
(let ((x-offset (car (gimp-drawable-offsets layer)))
(y-offset (cadr (gimp-drawable-offsets layer)))
(width (car (gimp-drawable-width layer)))
(height (car (gimp-drawable-height layer))))
; do some stuff here
; more stuff
)
You can execute the entire block by pasting it into the console, however, when debugging you will probably wish to execute some of the "stuff" line-by-line, using the values for the offsets and dimensions. To accomplish this, you need to convert them to 'define' statements:
(define x-offset (car (gimp-drawable-offsets layer)))
(define y-offset (cadr (gimp-drawable-offsets layer)))
(define width (car (gimp-drawable-width layer)))
(define height (car (gimp-drawable-height layer)))
While testing, I usually keep a second, temporary file open in my text editor to store these 'defined' versions of the bindings. I've also created a macro that saves some editing in creating such definitions.
(define-macro (dlet args)
(cons 'begin (map (lambda (x) (cons 'define x)) args)) )
With this macro defined, one can take the beginning of a 'let' declaration up to the end of the bindings, prepend a 'd' to the "let" and add a closing parenthesis to the end. Thus
(let ((x 10) (y 20) (z 30))
<body>
)
becomes:
(define x 10)
(define y 20)
(define z 30)