You are here

Would it be possible to make a script/plugin that does this...

hi,
just getting into gimp. thanks for all the cool scripts here.

I am using gimp to design user interfaces for VST audio plugins. I have made a layer for each knob, which i will hide when i export the background. I need to know the x/y coordinates of each of these layers in my plugin's gui code. Rather than manually work it all out, I wondered if it would be possible to make a script that ran through all the knob layers (i am using layer groups and all the knobs are k.*) and output a .txt file with the top left corner coordinates?

if it is possible, can anyone give me some clues about which functions to use or existing scripts to copy?

thanks very much

oli

Hi olilarkin

that should work. I'f you are using gimp under Windows, you have to redefine stdpath to (for example) "C:\\my_work" and stddelimiter to "\"

greetings Ruediger

---skriptfu---

(define stdpath "~")
(define stddelimiter "/")
(define stdfile "output.txt")

(define (script-fu-output-coords image drawable pathname filename)

(let* (
(thefile 0)
(file_and_path 0)
(coords 0)
(layername 0)

(layers (vector->list (cadr (gimp-image-get-layers image))))

)
(set! file_and_path (string-append pathname stddelimiter filename))

(set! thefile (open-output-file file_and_path))
(while (pair? layers)
(set! layername (gimp-drawable-get-name (car layers)))
(set! coords (gimp-drawable-offsets (car layers)))
(write (car coords) thefile)
(write-char #\space thefile)
(write (car (cdr coords)) thefile)
(write-char #\space thefile)
(write (car layername) thefile)
(newline thefile)

(set! layers (cdr layers))

)
(close-output-port thefile)

)

)

(script-fu-register "script-fu-output-coords"

"/Filters/Misc/Output Coordinates..."

"Outputs the coordinates of all layers"

"Rüdiger Schneider"

"Rüdiger Schneider"

"27 Oktober 2010"

"*"

SF-IMAGE "Image" 0

SF-DRAWABLE "Drawable" 0
SF-DIRNAME "Select Path" stdpath
SF-STRING "Enter filename" stdfile

)

---end skriptfu---

wow, thankyou very much, that works perfectly!

oli

Hi,
this one works better if your knob layers are bigger than the knob. The script autocrops the layers before writing the coordinates to the file.

---skriptfu---
(define stdpath "~")
(define stddelimiter "/")
(define stdfile "output.txt")

(define (script-fu-output-coords image drawable pathname filename)
(let* (
(thefile 0)
(file_and_path 0)
(coords 0)
(layername 0)
(layers (vector->list (cadr (gimp-image-get-layers image))))
)
(gimp-context-push)
(gimp-image-undo-group-start image)
(set! file_and_path (string-append pathname stddelimiter filename))
(set! thefile (open-output-file file_and_path))
(while (pair? layers)
(set! layername (gimp-drawable-get-name (car layers)))
(gimp-image-set-active-layer image (car layers))
(plug-in-autocrop-layer 1 image (car layers))
(set! coords (gimp-drawable-offsets (car layers)))
(write (car coords) thefile)
(write-char #\space thefile)
(write (car (cdr coords)) thefile)
(write-char #\space thefile)
(write (car layername) thefile)
(newline thefile)
(set! layers (cdr layers))
)
(close-output-port thefile)
(gimp-image-undo-group-end image)
(gimp-context-pop)
(gimp-displays-flush)
)
)

(script-fu-register "script-fu-output-coords"
"/Filters/Misc/Output Coordinates..."
"Outputs the coordinates of all layers"
"Rüdiger Schneider"
"Rüdiger Schneider"
"27 Oktober 2010"
"*"
SF-IMAGE "Image" 0
SF-DRAWABLE "Drawable" 0
SF-DIRNAME "Select Path" stdpath
SF-STRING "Enter filename" stdfile
)

---end skriptfu---

Subscribe to Comments for "Would it be possible to make a script/plugin that does this..."