GIMP Chat http://gimpchat.com/ |
|
PyScript to draw arrow http://gimpchat.com/viewtopic.php?f=9&t=15232 |
Page 1 of 2 |
Author: | Salamandre [ Tue Jan 31, 2017 9:05 pm ] | ||
Post subject: | PyScript to draw arrow | ||
Hi there, I made this python script (see attached file) that creates an arrow from a vectors. It is in <image>Filtre->Flecha I made it because I need to add arrows on building maps to indicate products movements. Here are other scripts that make arrows viewtopic.php?f=9&t=14617 http://chiselapp.com/user/saulgoode/rep ... troke-path It is fonctionnal but I am unhappy with few points. First few precision about how it works : - it uses the current image and current layer - it uses the current foreground color - it uses the current brush size (or so it should) - it uses the active vectors - it draws along the active vectors on a new layer - it makes a new layer on which it draws the spike - it moves and rotate the spike layer and merge it on the shaft layer - it drops the shadow if the foreground is not black - it merges the layer to the original one. What I do not like is that I was not able to use the tool to draw along the line that exists in the UI. I meen it had to use a brush instead of the feature that let me choose the style of extrmities and angeled turns. Secondly I could not select the tool with python, which results in a different behaviour of the script depending on the last tool I selected before drawing my vectors. Finally the size of the brush only works for the stencil tool. If you have any information, suggestions please let me know ![]() Salamandre Here after the code Code: Select all #!/usr/bin/python
|
Author: | Graechan [ Tue Jan 31, 2017 10:58 pm ] |
Post subject: | Re: PyScript to draw arrow |
It didn't draw an arrow head, all that resulted was the path being stroked with the current brush in the current brush-size and F/G color
|
Author: | Salamandre [ Tue Jan 31, 2017 11:20 pm ] |
Post subject: | Re: PyScript to draw arrow |
Maybe it drew the arrow so small that it is inside the line. You need to have selected this tool before using the script (it is one of the issues) ![]() so the width of the shaft is the brush size and the arrow is twice as big. The arrow you see on the image is made with the script for a width of 10. I use the brush size to make a quike script, with no option window. Tell me if it works |
Author: | Graechan [ Wed Feb 01, 2017 2:01 am ] |
Post subject: | Re: PyScript to draw arrow |
It was OK with the brush size set to 10 or greater
![]() |
Author: | ofnuts [ Wed Feb 01, 2017 2:46 am ] |
Post subject: | Re: PyScript to draw arrow |
Yes, there is no API to stroke a path in "Line" mode. I do have a script that does something similar, but it creates path strokes for the arrow heads and stops there. And this isn't so much of a problem, because the choices are rather open at that point (width, color, endings shape...) and to stroke the path in line mode would require a dialog about as complex as the "stroke path" dialog itself, with little added value. Btw, instead of using cmath.phase(), you should be using math.atan2(), and you can get a better estimate of the tangent by using the coordinates of the tangent handle... |
Author: | Salamandre [ Wed Feb 01, 2017 9:42 am ] |
Post subject: | Re: PyScript to draw arrow |
Hi, thanks for the answer. Could you show the script you'er talking about ? It was my first intention but I chose to keep it for a further version. Quote: Btw, instead of using cmath.phase(), you should be using math.atan2(), and you can get a better estimate of the tangent by using the coordinates of the tangent handle... Well, most of the time the tangent handle is on the last point (straight lines) so I didn't use that. But in this case I could make a conditional statement : - if both two last tangant handles are unused, use the angle of last straight line - if last tangant handle used, use it - if last tangant unused but previous tangant used, I see no other choice but to use my actual script. But you are right, it is a part of the script I should improve. |
Author: | Rod [ Wed Feb 01, 2017 2:25 pm ] |
Post subject: | Re: PyScript to draw arrow |
It is important to upload your python scripts in a zip folder as some users may not have the ability to properly indent python code with their text viewers. This way users can just place the python module in their plug-in folders and restart GIMP. Also if you could give the menu location in the first post for the filter? <Image>/Filters/Flecha This greatly helps users to find the plug-in in their GIMP menus. Thanks! ![]() |
Author: | Rod [ Wed Feb 01, 2017 2:37 pm ] |
Post subject: | Re: PyScript to draw arrow |
Worked fine for me first try. ![]() ![]() |
Author: | ofnuts [ Wed Feb 01, 2017 4:30 pm ] |
Post subject: | Re: PyScript to draw arrow |
Salamandre wrote: Hi, thanks for the answer. Could you show the script you'er talking about ? It was my first intention but I chose to keep it for a further version. See path-arrow-heads |
Author: | Graechan [ Wed Feb 01, 2017 6:00 pm ] |
Post subject: | Re: PyScript to draw arrow |
I think that the ability to add text to the arrow would be useful also
![]() |
Author: | Salamandre [ Wed Feb 01, 2017 10:03 pm ] |
Post subject: | Re: PyScript to draw arrow |
@ofnuts Thanks @ graechan Yes, it's en idea for a v2 or a brother script with options |
Author: | Rod [ Thu Feb 02, 2017 2:13 pm ] |
Post subject: | Re: PyScript to draw arrow |
Graechan wrote: I think that the ability to add text to the arrow would be useful also [ Image ] I think that is a good idea also. |
Author: | Salamandre [ Sun Feb 12, 2017 7:51 pm ] | ||
Post subject: | Re: PyScript to draw arrow | ||
Hello there, Here is the new version of my script (V1.1) ![]() Now you can either use it as perviously or choose the options in a window. Feel free to use it and to give me feedback ![]() Here are few issues for which I would like some help programming I had a problem puting special characters in the text of the options Code: Select all register( the "ñ" was preventing the script to be registered, so I took it off, but I would like to be able to put it. Is there a way to put the foreground color as the default color ? I keep in mind the idea to put a text on the arrow Thanks ! ![]() ![]()
|
Author: | ofnuts [ Mon Feb 13, 2017 2:57 am ] |
Post subject: | Re: PyScript to draw arrow |
1) It is a matter of declaring the proper encoding of the source code by adding something like: Code: Select all # -*- coding: utf-8 -*- as the second line of your script (use one or the other) (the first one should be "#!/usr/bin/env python") and of course encoding the file appropriately (if you are using a programmer's editor, it will recognize the line and encode the file properly). 2) No. Of course at registration time, you can obtain the current foreground value and use it in the registration call, but this can have changed when the user will invoke your script. So you either have a selector that says "Current Foreground"/"Specific color" or just use the foreground (which is how most tools work...). Side note: if you publish on the web, better have code in English (names of functions/variables, comments) as well as a version with an English UI. |
Author: | Salamandre [ Mon Feb 13, 2017 10:02 pm ] |
Post subject: | Re: PyScript to draw arrow |
Thanks Ofnuts ! For the language I have to makr the ui in Spanish, but I like to share. I have not investigated yet if there is a way to register translations of the texts, so if you installed gimp in english, my script would show in english. |
Author: | Salamandre [ Tue Feb 28, 2017 9:26 pm ] | ||
Post subject: | Re: PyScript to draw arrow | ||
Hello there ! Here is the V2.0 of my script ! ![]() ![]() Caution : it works with the text_along_path script modified by me (I join it too) What's new? It has been translated to english You can put a text on the arrow Any feedback welcome ![]() Hey Ofnuts, I have modified your script so the declared function returns the vectors created. What do you think of it ? You can see my modifications by looking for the "#modif perso" coments. I join the script and copy past it here after. Code: Select all #!/usr/bin/python
|
Author: | Graechan [ Wed Mar 01, 2017 1:00 am ] |
Post subject: | Re: PyScript to draw arrow |
It workedwith a bit of effort but when used from both menu locations had errors ![]() Quote: GIMP Warning Plug-In 'Quike arrow' left image undo in inconsistent state, closing open undo groups. GIMP Error Calling error for procedure 'gimp-vectors-to-selection': Procedure 'gimp-vectors-to-selection' has been called with value '-1' for argument 'vectors' (#1, type GimpVectorsID). This value is out of range. GIMP Warning Plug-In 'Arrow' left image undo in inconsistent state, closing open undo groups. Quote: GIMP Error
Calling error for procedure 'gimp-vectors-to-selection': Procedure 'gimp-vectors-to-selection' has been called with value '-1' for argument 'vectors' (#1, type GimpVectorsID). This value is out of range. GIMP Warning Plug-In 'Arrow' left image undo in inconsistent state, closing open undo groups. |
Author: | ofnuts [ Wed Mar 01, 2017 2:54 am ] |
Post subject: | Re: PyScript to draw arrow |
Salamandre wrote: Hello there ! Hey Ofnuts, I have modified your script so the declared function returns the vectors created. What do you think of it ? You can see my modifications by looking for the "#modif perso" coments. You do whatever you want with my code but you shouldn't be distributing text-to-path-0.5, but duclos-text-to-path-0.0 (or steal code from it...). If you distribute it it's yours. I'm not returning a path because I can create several paths depending on options. This said the path created is the one at the top of the path list (image.vectors[0]) so if this is your only mod, you can use the original version. |
Author: | Salamandre [ Sat Mar 04, 2017 4:31 pm ] | ||
Post subject: | Re: PyScript to draw arrow | ||
@Graechan maybe it is because of using the text along path v0.4. But here is the v2.1 of my script that works OK. @Ofnuts No I prefer to modify my script to make it work with yours as such. I think duplicating scripts or "stealing" codes is counter productive. However, a procedure that creates objects (in your case vectors) should either destroy them before ending or return them as values. In the first part of my script, I tried to put a verification to see if the script text_along_path_full was there, and to inform the user if not. Code: Select all #if "python_fu_text_along_path_full" in dir(pdb): But it doesn't work. Someone knows an other way to reach this goal ?
|
Author: | Graechan [ Sat Mar 04, 2017 6:43 pm ] |
Post subject: | Re: PyScript to draw arrow |
Salamandre both Menu entries work nicely now but do we still need 'text-along-path-0.5.py' installed
Edit no it doesn't as it works fine without it |
Page 1 of 2 | All times are UTC - 5 hours [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |