2011-06-28 78 views
2

我此腳本是瘸子的.scm:爲什麼GIMP不能處理這個腳本?

;MIT license. 

(define (script-fu-export-layers img drw path outnameformat) 
; credit to Vijay Mathew on Stack Overflow for the expand keywords function 
    (let ((expand-keywords (lambda(format tokens) 
    (let loop ((slist (string->list string)) 
       (in-replace-mode #f) 
       (result "")) 
     (if (not (null? slist)) 
      (let ((c (car slist))) 
      (cond (in-replace-mode 
        (let ((token (car (cdr (assoc c tokens))))) 
        (loop (cdr slist) #f (string-append result token)))) 
        ((char=? C#\~) 
        (loop (cdr slist) #t result)) 
        (else 
        (loop (cdr slist) #f (
         string-append result (make-string 1 c)))))) 
      result))))) 
    (for-each (lambda (layer) 
    (let* (
     (name (expand-keywords outnameformat '(
      (#\i (car(gimp-image-get-name img))) 
      (#\l (car(gimp-drawable-get-name layer)))))) 
     (outpath (string-append path "/" name))) 
     (gimp-file-save RUN-NONINTERACTIVE img layer outpath name) 
)) (vector->list(cadr (gimp-image-get-layers img))))) 
) 

(script-fu-register 
    "script-fu-export-layers" 
    "L_ayers" 
    "Export all layers as individual files." 
    "Stuart P. Bentley <[email protected]>" 
    "Copyright 2011 Stuart P. Bentley" 
    "June 28, 2011" 
    "*" 
    SF-IMAGE  "The Image"   0 
    SF-DRAWABLE "The Layer"   0 
    SF-DIRNAME  "Output directory" "" 
    SF-STRING  "Filename Format (~i = image name, ~l = layer name)" 
                  "~i-~l.png" 
) 
(script-fu-menu-register "script-fu-export-layers" "<Image>/File/E_xport") 

隨着在文件頂部的註釋,該腳本不會加載。刪除註釋時,GIMP在刷新腳本時出現錯誤:「加載C:\ Users \ Stuart.gimp-2.6 \ scripts \ export-layers.scm時出錯:錯誤:不匹配的圓括號:1」。我不知道那是怎麼一回事,因爲當我在鍵盤上運行它時,它解析得很好(它在腳本 - 註冊點處斷開)。

+3

如果它在第一條評論中嘔吐,你有沒有嘗試';信用評論? –

+0

@Alex K .: D'oh。這讓我走上了解決問題的正確軌道。 –

+1

最終腳本在http://registry.gimp.org/node/25394的GIMP插件註冊表中列出。 –

回答

3

此行爲與如果行結尾丟失(評論註釋掉所有後續文本)會發生什麼一致。請檢查以確保您的編輯器不會像在Windows上使用CR行結尾保存文件那樣荒謬。

+1

不,不是LF行結尾 - * CR *,就像「Mac OS曾經使用的種類,即使在十多年後還沒有使用過」。 –

相關問題