0

我正在编写我的第一个脚本,方案对我来说仍然不是很清楚。

我的脚本工作正常,但我想添加一个其他参数(仅可见),我有一行在某个地方导致非法函数错误,但在其他地方没有。

感谢您的帮助 :-)

这是我的台词:

(display " onlyvisible: ")(display onlyvisible)(newline)

这是我的代码:

(define (pitibalrog-test img filename onlyvisible)
(let*
    (
        (imgcopy (car ( gimp-image-duplicate img))) ; Copy to avoid changes on the original image
    )
    (display " onlyvisible: ")(display onlyvisible)(newline)
    (pitibalrog-export-layers imgcopy (gimp-image-get-layers imgcopy) filename onlyvisible) 
)
)


(define (pitibalrog-export-layers img listlayers filename onlyvisible)
(let*
    (
        (nblayers (car listlayers))
        (layers (cadr listlayers))
        (display "EXPORT LAYERS: LAYERS = ")(display layers)(newline)

        (display " onlyvisible: ")(display onlyvisible)(newline) ; <--- HERE IT WORKS
        (index 0)

        (basename (unbreakupstr (butlast (strbreakup filename ".")) "."))
        (extension (car (last (strbreakup filename "."))))
        (layer)
    )

    (display " onlyvisible: ")(display onlyvisible)(newline) ; <--- HERE IS THE PROBLEM


    (while (< index nblayers)
        (set! layer (aref layers index))
        (gimp-item-set-visible layer FALSE)
        (set! index (+ index 1))
    )
    (set! index 0)
    (while (< index nblayers)
        (set! layer (aref layers index))
        (set! filename (string-append basename (car(gimp-drawable-get-name layer)) "." extension))

        (pitibalrog-export-layer img layer filename onlyvisible)

        (set! index (+ index 1))
    )
)
)

(define (pitibalrog-export-layer img layer filename onlyvisible)
    (display " - export layer: ")(display layer)(newline)

    (gimp-item-set-visible layer TRUE)

    ; LAYER GROUP
    (when (= (car(gimp-item-is-group layer)) 1)
        (display "Layer ")(display layer)(display " is a group")(newline)
        (pitibalrog-export-layers img (gimp-item-get-children layer) filename onlyvisible)
    )
    ; REAL LAYER
    (when (= (car(gimp-item-is-group layer)) 0)
        (display "Layer ")(display layer)(display " is not a group")(newline)
        ; (gimp-file-save RUN-NONINTERACTIVE img layer filename filename) ; NO MASK HANDLING!!!
        (gimp-file-save RUN-WITH-LAST-VALS img layer filename filename)
    )

    (gimp-item-set-visible layer FALSE)
)

(script-fu-register "pitibalrog-test"
"<Image>/Script-Fu/Utils/pitibalrog-test..."
"Export all layers of the image in separete files" ;comment
"pitiBalrog" ;author
"pitiBalrog" ;copyright
"November 2012" ;date
"*A"
SF-IMAGE "img" 0
SF-FILENAME "destination" ""
SF-TOGGLE   "Export only visible layers" TRUE
)
4

1 回答 1

1

免责声明:我从来没有用 script-fu 做过任何工作,所以我不知道那些 script-fu 特定的程序是做什么的。计划,但是,我可以做到。

请仔细查看let特殊形式所需的语法:

(let <List of forms that assign values>
   <body>)

我认为您的主要问题来自这样一个事实,即在方案中您可以更改几乎任何东西的值——像其他语言一样,保留字很少。所以,当你说(let ((display 3)) <body>),display不再指向向 REPL 显示东西的过程。然后,在你的正文中,let*当你说(display " onlyvisible")你试图调用一个不是函数的函数时——在这种情况下,不管值layers是什么。

一般来说,所有需要做类似事情的代码都display应该在函数体中。例如:

(let ((foo 3)                 ; associate symbol foo with the value 3
      (bar "I'm a string!")   ; associate symbol bar with a string
      (* '(a b c)))           ; associate symbol * with a list '(a b c)
  (display foo)               ;\
  (newline)                   ; \    
  (display bar))              ;  }-- expressions that make up the body
  (newline)                   ;  /
  (display *)                 ; /
  (* 3 4))                    ;/ --- this is the same type of error you made

;;Output
3
I'm a string!
(a b c)
ERROR -- invalid function

最后,请不要像 C 或 Java 等那样格式化方案代码。这是第一个过程的方案友好版本:

(define (pitibalrog-test img filename onlyvisible)
  (let ((img copy (car (gimp-image-duplicate img))))
    (display " onlyvisible: ")
    (display onlyvisible)
    (newline)
    (pitibalrog-export-layers imgcopy (gimp-image-get-layers imgcopy) filename onlyvisible)))

格式良好的代码使策划者感到高兴,并且您更有可能获得快速帮助。

于 2012-11-27T04:55:37.780 回答