Posts: 5
Threads: 2
Joined: Sep 2023
Reputation:
0
09-13-2023, 12:25 AM
(This post was last modified: 09-13-2023, 12:31 AM by Strzegol.)
Hello. Still another newbie question. Why this script don't work? (GIMP 2.99 but this is so basic stuff that this should don't matter)
EDIT: I checked documentations for hours and also mined examples shipped with GIMP but there are no examples that use gimp-paintbrush-default and oddly I don't found anything in documentation about creation of scripts that draw something on existing images despite this kind of scripts seems to be most common)
EDIT: It should draw line from cornet to pixel at x=100 y=100 using current brush.
Code:
(define (script-fu-linedraw drawable orientation)
(gimp-paintbrush-default drawable 2 #(0 0 100 100))
)
(script-fu-register
"script-fu-linedraw"
"Linedraw"
"Try draw a line in GIMP"
"Strzegol"
"copyright 2023 Strzegol"
"September 12,2023"
""
SF-DRAWABLE "Drawable" 0
)
(script-fu-menu-register "script-fu-linedraw"
"<Image>/Tools")
Second stuff: Why refreshing scripts remove them from menu?
Posts: 6,343
Threads: 274
Joined: Oct 2016
Reputation:
564
Operating system(s):
Gimp version: 2.10
(09-13-2023, 12:25 AM)Strzegol Wrote: Hello. Still another newbie question. Why this script don't work? (GIMP 2.99 but this is so basic stuff that this should don't matter)
EDIT: I checked documentations for hours and also mined examples shipped with GIMP but there are no examples that use gimp-paintbrush-default and oddly I don't found anything in documentation about creation of scripts that draw something on existing images despite this kind of scripts seems to be most common)
EDIT: It should draw line from cornet to pixel at x=100 y=100 using current brush.
Code:
(define (script-fu-linedraw drawable orientation)
(gimp-paintbrush-default drawable 2 #(0 0 100 100))
)
(script-fu-register
"script-fu-linedraw"
"Linedraw"
"Try draw a line in GIMP"
"Strzegol"
"copyright 2023 Strzegol"
"September 12,2023"
""
SF-DRAWABLE "Drawable" 0
)
(script-fu-menu-register "script-fu-linedraw"
"<Image>/Tools")
Second stuff: Why refreshing scripts remove them from menu?
The catch is that the num_strokes parameter is the number of coordinates, not the number of strokes (so, the size of the list...). So in your case it should be 4, not 2.
Refreshing scripts re-runs them for registration, so my guess is that if they contain syntax errors, they can't run, so are deregistered.
Posts: 5
Threads: 2
Joined: Sep 2023
Reputation:
0
(09-13-2023, 07:26 AM)Ofnuts Wrote: The catch is that the num_strokes parameter is the number of coordinates, not the number of strokes (so, the size of the list...). So in your case it should be 4, not 2.
Refreshing scripts re-runs them for registration, so my guess is that if they contain syntax errors, they can't run, so are deregistered.
1. I would say that this is simple size of array. Because coordinates are two. Stroke is one. (In my example).
2,Then how is possible that these scripts were registered at GIMP start, worked fine and get deregistered at refreshing WITHOUT any change to them?
3.How to create a variable of type "GimpFloatArray" from code? Why this is not documented? Why when I do this:
Code:
(define (script-fu-foobar image drawable orientation)
(let*
(
(area-width 1000)
(area-height 1000)
)
(gimp-paintbrush-default drawable 4 '#(0 0 area-width area-height))
(gimp-displays-flush)
)
)
Them GIMP complain that:
Code:
Error: in script, expected type: numeric for element 3 of argument 3 to gimp-paintbrush-default #(0 0 area-width area-height)
But when I (print area-width) before (gimp-paintbrush...) it display 1000 so what is "numeric" then?
Posts: 6,343
Threads: 274
Joined: Oct 2016
Reputation:
564
Operating system(s):
Gimp version: 2.10
(09-14-2023, 01:32 AM)Strzegol Wrote: (09-13-2023, 07:26 AM)Ofnuts Wrote: The catch is that the num_strokes parameter is the number of coordinates, not the number of strokes (so, the size of the list...). So in your case it should be 4, not 2.
Refreshing scripts re-runs them for registration, so my guess is that if they contain syntax errors, they can't run, so are deregistered.
1. I would say that this is simple size of array. Because coordinates are two. Stroke is one. (In my example).
2,Then how is possible that these scripts were registered at GIMP start, worked fine and get deregistered at refreshing WITHOUT any change to them?
3.How to create a variable of type "GimpFloatArray" from code? Why this is not documented? Why when I do this:
Code:
(define (script-fu-foobar image drawable orientation)
(let*
(
(area-width 1000)
(area-height 1000)
)
(gimp-paintbrush-default drawable 4 '#(0 0 area-width area-height))
(gimp-displays-flush)
)
)
Them GIMP complain that:
Code:
Error: in script, expected type: numeric for element 3 of argument 3 to gimp-paintbrush-default #(0 0 area-width area-height)
But when I (print area-width) before (gimp-paintbrush...) it display 1000 so what is "numeric" then?
I dearly hate script-fu.... this said when I look for example on the internet, most allocate arrays and plug values in it:
Code:
(let *
(
(points (cons-array 4 'double))
(ax 100)
(ay 100)
(bx 300)
(by 300)
)
(aset points 0 ax)
(aset points 1 ay)
(aset points 2 bx)
(aset points 3 by)
(gimp-paintbrush-default layerId 4 points)
)
You understand why I use Python...
Posts: 301
Threads: 12
Joined: Oct 2016
Reputation:
16
Operating system(s):
- Windows (Vista and later)
Gimp version: 2.10
I would suggest that expecting anything to work on any particular instance of 2.99 is not a good idea.
Refreshing scripts is broken, and probably won't be fixed: https://gitlab.gnome.org/GNOME/gimp/-/issues/7445
Posts: 5
Threads: 2
Joined: Sep 2023
Reputation:
0
Guys I thank for all your answers!
Quote:
I dearly hate script-fu.... this said when I look for example on the internet, most allocate arrays and plug values in it:
Code:
(let *
(
(points (cons-array 4 'double))
(ax 100)
(ay 100)
(bx 300)
(by 300)
)
(aset points 0 ax)
(aset points 1 ay)
(aset points 2 bx)
(aset points 3 by)
(gimp-paintbrush-default layerId 4 points)
)
I found that changing "
Code:
'#(0 0 area-width area-height)
To:
Code:
(vector 0 0 area-width area-height)
Helps. I don't know why.
Quote:You understand why I use Python...
I don't think that this is a Scheme problem. This is problem with incomplete documentation of API, and this is problem shared with Python-Fu. In fact, I toy with though of writing myself short tutorial because I figured already some stuff that is not documented.
And I have experience with many languages, including Python and Scheme, and I selected Scheme because Python-Fu has even less documentation than Script-Fu.
Quote:I would suggest that expecting anything to work on any particular instance of 2.99 is not a good idea.
Refreshing scripts is broken, and probably won't be fixed: https://gitlab.gnome.org/GNOME/gimp/-/issues/7445
Gimp 2.1x use GTK 2.0 that is no longer maintained. It has problems with handling never tablet drivers.
|