Switch to full style
Post all Gimp scripts and script writing questions here
Post a reply

Problem with a script-fu

Tue Jun 14, 2016 10:45 am

Hello,
I want to convert files with the extension .png to .gbr format on batch. To do that I used a script found on the web: brush-batch.scm. This one does not work on my computer that is why I used it to create a new one. My code is lauching but it stops during loading file.
If you can help me to understand why that could be great.

This is my code:
(define (convert-pngtogbr load name location)


(gimp-context-set-foreground '(0 0 0))
(gimp-context-set-background '(255 255 255))
(let* (
(filelist (cadr (file-glob (string-append load "\\*.png") 1)))
(s 1)
)
(while filelist
(let* (
(loadfile (car filelist))
(image (car (gimp-file-load RUN-NONINTERACTIVE loadfile loadfile)))
)
(set! drawable (gimp-image-get-active-drawable image))
(set! filename2 (string-append location "/" name ".gbr"
))
(file-gbr-save 1 image drawable filename2 name 15 name))
(set! s (+ s 1))
(gimp-image-delete (car image))
(set! filelist (cdr filelist))))
)
(script-fu-register "convert-pngtogbr"
"<Toolbox>/Xtns/Script-Fu/PngToGbr..."
"Convert png to gbr"
"XX"
"XX"
"Juin 2016"
""
SF-DIRNAME "Load from" ""
SF-STRING "Brush Name" "name"
SF-DIRNAME "SAVE TO FOLDER" "")


Thank you very much
Best regards
Tahoser

Re: Problem with a script-fu

Tue Jun 14, 2016 11:24 am

It's so much easier to read if you put it in [ code ] tags:
Code:
(define (convert-pngtogbr load name location)
  (gimp-context-set-foreground '(0 0 0))
  (gimp-context-set-background '(255 255 255))
  (let*
    (
      (filelist (cadr (file-glob (string-append load "\\*.png") 1)))
      (s 1)
    )
    (while filelist
      (let*
        (
          (loadfile (car filelist))
          (image (car (gimp-file-load RUN-NONINTERACTIVE loadfile loadfile)))
        )
        (set! drawable (gimp-image-get-active-drawable image))
        (set! filename2 (string-append location "/" name ".gbr"))
        (file-gbr-save 1 image drawable filename2 name 15 name)
      )
      (set! s (+ s 1))
      (gimp-image-delete (car image))
      (set! filelist (cdr filelist))
    )
  )
)

(script-fu-register "convert-pngtogbr"
"<Toolbox>/Xtns/Script-Fu/PngToGbr..."
"Convert png to gbr"
"XX"
"XX"
"Juin 2016"
""
SF-DIRNAME "Load from" ""
SF-STRING "Brush Name" "name"
SF-DIRNAME "SAVE TO FOLDER" "")


I've not tried it, but one obvious problem is that you've not defined drawable or filename2 before using them.

Kevin

Re: Problem with a script-fu

Wed Jun 15, 2016 4:28 am

Thank you for your information about code tag. I will use it now.

filename2 is defined as that:
Code:
(set! filename2 (string-append location "/" name ".gbr"))


and drawable as that:
Code:
(set! drawable (gimp-image-get-active-drawable image))


The problem seems to come from uploading file. On the screen, the dialog box closes at that time.

Thank you

Best regards
Tahoser

Re: Problem with a script-fu

Wed Jun 15, 2016 5:21 am

tahoser wrote:Thank you for your information about code tag. I will use it now.

filename2 is defined as that:
Code:
(set! filename2 (string-append location "/" name ".gbr"))


and drawable as that:
Code:
(set! drawable (gimp-image-get-active-drawable image))



No!

You have to define something BEFORE you use set!

otherwise you get this:
Code:
> (set! fred 1)
Error: set!: unbound variable: fred


Kevin

Re: Problem with a script-fu

Wed Jun 15, 2016 8:21 am

OK. Do you have an example?
I join the code I used because I did not understand where and how I have to do what you said.

Thank you
Post a reply