![]() |
Troubles with porting a script to Gimp3 - Printable Version +- Gimp-Forum.net (https://www.gimp-forum.net) +-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP) +--- Forum: Extending the GIMP (https://www.gimp-forum.net/Forum-Extending-the-GIMP) +---- Forum: Scripting questions (https://www.gimp-forum.net/Forum-Scripting-questions) +---- Thread: Troubles with porting a script to Gimp3 (/Thread-Troubles-with-porting-a-script-to-Gimp3) |
Troubles with porting a script to Gimp3 - alvk - 03-03-2025 Hello! I have trouble with porting a script written in Script-Fu from Gimp2 to Gimp3. I managed to run the script, but when script execution finished, I've got the following error: argument 1 must be: number. Unfortunately, I cannot understand why this error occurs. Could anyone review my code and help me to make the script working. The script is below: Code: #!/usr/bin/env gimp-script-fu-interpreter-3.0 RE: Troubles with porting a script to Gimp3 - Ofnuts - 03-03-2025 You sprinkle the code with identifiable calls to (print ...) (if running from the script-fu console) or (gimp-message ...) (if running from the menus) and you can quickly determine between which print/gimp-message calls the error occurs, which should lead you to the culprit... RE: Troubles with porting a script to Gimp3 - alvk - 03-04-2025 (03-03-2025, 11:37 AM)Ofnuts Wrote: You sprinkle the code with identifiable calls to (print ...) (if running from the script-fu console) or (gimp-message ...) (if running from the menus) and you can quickly determine between which print/gimp-message calls the error occurs, which should lead you to the culprit... Thank you for your reply. I was trying to find where the error occurs in the code, but with no success. I have reverted some code to the one that was working in Gimp2. Here it is: Code: (let* ((off-x (car (gimp-drawable-get-offsets drawables))) With these changes in the script, posted earlier, I can start Gimp normally and run the script. But now I've got another error: "Error: in script, expected type: numeric for argument 1 to gimp-drawable-get-offsets". This error appears when the script executes gimp- drawable-get-offsets for the first time. Now I can't understand why this error occurs. In Gimp console, if I run the following code: Code: (define (off-x x) (car (gimp-drawable-get-offsets x))) I can get the correct result, when providing the function with correct drawable. However, I can't understand why I'm getting an error in the script. RE: Troubles with porting a script to Gimp3 - alvk - 03-04-2025 After searching for internet, I came to the following code: Code: (let* ((off-x (car (gimp-drawable-get-offsets (vector-ref drawables 0)))) But still, I've got another error saying that car: argument 1 must be: pair when assigns off-x variable. Could anyone explain what is wrong with this code. RE: Troubles with porting a script to Gimp3 - Ofnuts - 03-04-2025 In Gimp3 your "drawables" argument is a list (or a vector) of drawables and no longer a unique drawable. So either you iterate the list (if you accept desveral drawables) or you pick the fist element. There are registration flags to tell if you accept 0, 1, or more drawables. RE: Troubles with porting a script to Gimp3 - alvk - 03-05-2025 (03-04-2025, 03:50 PM)Ofnuts Wrote: In Gimp3 your "drawables" argument is a list (or a vector) of drawables and no longer a unique drawable. So either you iterate the list (if you accept desveral drawables) or you pick the fist element. There are registration flags to tell if you accept 0, 1, or more drawables. Thank you for your suggestion. I have included the flag SF-ONE-DRAWABLE, but nothing has changed. After more careful reading, I came to the following. If I use v3 dialect of Script-Fu, i.e., by inserting the following code at the top of the script: Code: (script-fu-use-v3) https://www.gimp-forum.net/Thread-Script-fu-V3-plug-ins I get the following error: Code: car: argument 1 must be: pair Code: Error: runtime: resource ID of improper subclass. (1 2573) Code: (let* ((off-x (car (gimp-drawable-get-offsets (vector-ref drawables 0)))) RE: Troubles with porting a script to Gimp3 - Ofnuts - 03-05-2025 SF-ONE-DRAWABLE doesn't change the structure of the script arguments (you still get a list, even if it has only one element). It is only a flag used by the UI to enable/disable the menu entry depending on application state (and technically, you would still have to check that you have only one drawable in th elist, because you could hypothetically be called by another script that could ignore the flag. RE: Troubles with porting a script to Gimp3 - alvk - 03-05-2025 (03-05-2025, 07:41 AM)Ofnuts Wrote: SF-ONE-DRAWABLE doesn't change the structure of the script arguments (you still get a list, even if it has only one element). It is only a flag used by the UI to enable/disable the menu entry depending on application state (and technically, you would still have to check that you have only one drawable in th elist, because you could hypothetically be called by another script that could ignore the flag. Thank you for your suggestion. I have almost re-written the script into Script-Fu v.3 dialect. But now I have another problem. The following code is expected to check whether the drawable is a group, a layer mask, a selection, or a text layer to prevent the text to be added to either of these. Code: (cond (#t (gimp-item-is-group (vector-ref drawables 0))) (set! parent-layer-type 1) However, this code always sets the parent-layer-type to 0, even when drawable is a normal layer. Unfortunately, with this code, I cannot figure out how to select active drawable. Interestingly, that this code works fine and selects active drawable Code: (layer-width (gimp-drawable-get-width (vector-ref drawables 0))) Am I missing something with the conditional code? RE: Troubles with porting a script to Gimp3 - Ofnuts - 03-05-2025 I can help with the API, but not with Scheme... If I had to do something like this, i would rewrite the whole thing in Python... RE: Troubles with porting a script to Gimp3 - alvk - 03-05-2025 (03-05-2025, 05:26 PM)Ofnuts Wrote: I can help with the API, but not with Scheme... If I had to do something like this, i would rewrite the whole thing in Python... I agree with you, that Python would be better, but I'm not a programmer and rewriting this code in Python is far beyond my expertise. Anyway, thank you for your suggestions. You helped me a lot. |