我正忙着写一个Script-fu并继续“错误(:1)非法功能”。我不是Scheme / Lisp专家,只是试图自动化一些摄影任务。文档很少 - 要么GiMP只写自己的内部动作,而不是Script-fu中的Scheme的语法,或者我找到GiMP v1.0的“提示”(即这样过时它们没用)。
我查看了一系列随GiMP提供的脚本,试图了解更多并弄清楚这一点,但无济于事。我在这里请求帮助以删除错误,不缩进布局或Python-fu存在的事实等。
然后,代码(缩减为功能骨架):
;;
;; license, author, blah blah
;; FOR ILLUSTRATION PURPOSES
;; GiMP 2.8 LinuxMint 18.1
;; does the work, but then blows up saying "Error ( : 1) illegal function"
;;
(define (script-fu-ScriptFails InImage InLayer pickd mrge)
(let* (
(CopyLayer (car (gimp-layer-copy InLayer TRUE)) )
)
(gimp-image-undo-group-start InImage)
(gimp-image-add-layer InImage CopyLayer -1)
(gimp-drawable-set-visible CopyLayer TRUE)
;; Perform CHOSEN action on CopyLayer
(if (equal? pickd 0) ( ;; keep just the RED
(plug-in-colors-channel-mixer TRUE InImage CopyLayer FALSE 1.0 0 0 0 0 0 0 0 0)
(gimp-drawable-set-name CopyLayer "RED")
))
(if (equal? pickd 1) ( ;; keep just the GREEN
(plug-in-colors-channel-mixer TRUE InImage CopyLayer FALSE 0 0 0 0 1.0 0 0 0 0)
(gimp-drawable-set-name CopyLayer "GRN")
))
(if (equal? pickd 2) ( ;; keep just the BLUE
(plug-in-colors-channel-mixer TRUE InImage CopyLayer FALSE 0 0 0 0 0 0 0 0 1.0)
(gimp-drawable-set-name CopyLayer "BLU")
))
(if (equal? mrge #t) ( ;; to merge or not to merge
(gimp-layers-flatten InImage)
))
(gimp-image-undo-group-end InImage)
(gimp-display-flush)
)
)
(script-fu-register "script-fu-ScriptFails"
_"<Image>/Script-Fu/ScriptFails..."
"Runs but fails at the end. Why? Please help!"
"JK"
"(pop-zip,G-N-U)"
"2016.12"
"RGB*"
SF-IMAGE "The Image" 0
SF-DRAWABLE "The Layer" 0
;; other variables:
SF-OPTION "Effect" '("R_ed" "G_rn" "B_lu")
SF-TOGGLE "Merge Layers" FALSE
)
答案 0 :(得分:1)
看起来您使用括号作为块。例如:
(if (equal? pickd 2) ( ;; keep just the BLUE
(plug-in-colors-channel-mixer TRUE InImage CopyLayer FALSE 0 0 0 0 0 0 0 0 1.0)
(gimp-drawable-set-name CopyLayer "BLU")
))
你看到关于保持蓝色的评论之前的开场白吗?那意味着你这样做:
((plu-in....) (gimp-drawable...))
第一个当然需要返回一个有效的Scheme函数,而第二个函数的返回值是提供的参数。如果你想因为它们的副作用而做两个表达式,那么你应该使用一个块。与C方言中的curlies一样,块是以Scheme:
中的begin
开头的形式
(begin
(plu-in....)
(gimp-drawable...))
因此,这将评估表达式,如果它也是函数的尾部,那么最后一个表达式的结果就是结果。
同样对if
只有后果而且没有使用when
的替代方案会给你一个开头:
(when (equal? pickd 2) ;; keep just the BLUE (and no extra parens)
(plug-in-colors-channel-mixer TRUE InImage CopyLayer FALSE 0 0 0 0 0 0 0 0 1.0)
(gimp-drawable-set-name CopyLayer "BLU"))