I'm trying to write an extension for Inkscape 1.0+ which will call the Path->Simplify method on a list of selected paths. I know I can select multiple paths and then do Path->Simplify on the set, but that results in the shape being distorted as the selection set is too large. I want to do the minimum reduction of excess nodes in each path without affecting the shape significantly. Currently I'm manually selecting each path then doing Path->Simplify on it. This becomes very tedious in a file with lots of paths.
Is there a way for an extension to call Path->Simplify on a selection set, or is there some other way of doing it?
You can access other extensions from an extension by using 'import' in the normal way.
However functions which are part of the inkscape api cannot be directly used by an extension.
You can use the inkscape command module to call them but, it's more of a trick which involves calling the inkscape command line from within the extension.
It is possible to avoid all this by writing a batch file for the inkscape command line to loop through all the paths in the document and apply simplify, but you wouldn't really have the same control as using a selection.
Excellent!. I grabbed that extension and modified it to add a simplify operation. It still seems to be changing the geometry somewhat. I'll delve a bit further.
FYI, the purpose of this is to reduce the number of superfluous nodes in a path as they make my laser cutter freak out.
I'm just doing a regular object to path operation, but with certain fonts, the resultant path has a lot of superfluous nodes as seen in my screenshot above. This shows the nodes before and after simplification. I suppose it must be something to do with the way some fonts store their glyphs.
Hej Fergal, Your extension is great news. Does the extension also get rid of the double nodes (on top of each other)? After Bolean path operations and also after using the bucket fill tool I see those double nodes everywhere.
Unfortunately not. My extension just calls Path->Simplify which does not join double nodes AFAIK. There's probably another extension that does that, or may some built in function that I don't know about.
I tried that extension and it doesn't seem to join double nodes. Tried with Inkscape 1.0.2. Also with Inkscape 1.1 I get a deprecation warning. If I do SHIFT+J on the highlighted double node, it works as expected.
It turns out I somehow had three duplicates stacked up.
However after deleting the surplus ones, CTRL+A then SHIFT+J, didn't merge any of the double nodes. If I select them individually it does work though. This applies to v1.0.2 & v1.1. I haven't tried on v0.9.2 which is my go to version as it seems to be much more stable than the v1.x releases. I've just been experimenting with the newer versions for the new functionality.
I'm working on an update to the removeduplicatenodes to add more functions. I wrote it for version 1.0 or higher, but have not worked on it for a while so maybe more is becoming depricated now than before. I will look into that. I will also run tests with more than duplicates to make it work for that too. Just have to come up with all options to test...
I'm happy to help test it. Just let me know what you need.
BTW thanks for all the info about stroke fonts you have on your website. When I first got my laser cutter 6 months ago I was on a quest for those kind of fonts, and found your website to be a valuable source of information.
Now I finally found some time to work on the removeDuplicateNodes extension - updating it for v1.1 concerning the deprication warning and also finalizing some bugfixes and extra options. So if someone would like to test it ( @fergal ?) the new version can be found here:
Did you have the interpolate option off? Sometimes there is a little discrepancy within the duplicates and the upper option to interpolate with a discrepancy can be used with a small number to force joining the points. Often this is within the 7th decimal...so interpolating will not do much, just make it happen. Or you could send me the SVG and I'll troubleshoot.
Here's a screenshot of my settings. I increased the join distance to 0.1 and that helped find the duplicates, so it must be a math rounding error. I also tried reversing the direction of the top arc segment. This produced unexpected results. I was hoping it would just reverse the direction of that segment so that the path was continuous around the shape. What I'm trying to achieve is to optimize the path for laser cutting so that the laser head moves in one continuous path as much as possible without jumping around or going back on itself. I'd like to get my files as optimal as possible in Inkscape rather than relying on the laser cutter software to do the optimization. I've also attached the SVG.
When selecting all paths in your file and having the same settings as you I get the expected result (see attached). For the upper object where all paths are combined, the algorithm will evaluate those in relation to each other. For the lower object where there are separate paths nothing happens as the paths are seen one by one. Now the question is why this work differently on my computer compared to yours. I'm on Windows 10, inkscape v1.1. And you?
There's something strange going on. I reordered the segments so that the one with the reversed path was at the bottom of the stack instead of at the top in the object view, then did Path->Combine, then ran your extension and got this result.
With reversing the top path and moving that to bottom of the stack - I could also reproduce strange results (though not equal to yours). I'll look more into that. I could not replicate the problem with other reverse and reorder. With the "allow for reverse" option selected you should not need to do the reversing yourself. I'll have to troubleshoot.
Hi
I'm trying to write an extension for Inkscape 1.0+ which will call the Path->Simplify method on a list of selected paths. I know I can select multiple paths and then do Path->Simplify on the set, but that results in the shape being distorted as the selection set is too large. I want to do the minimum reduction of excess nodes in each path without affecting the shape significantly. Currently I'm manually selecting each path then doing Path->Simplify on it. This becomes very tedious in a file with lots of paths.
Is there a way for an extension to call Path->Simplify on a selection set, or is there some other way of doing it?
Thanks
Fergal
You can access other extensions from an extension by using 'import' in the normal way.
However functions which are part of the inkscape api cannot be directly used by an extension.
You can use the inkscape command module to call them but, it's more of a trick which involves calling the inkscape command line from within the extension.
This extension https://inkscape.org/~Moini/%E2%98%85multiple-boolean-operations-with-inx-pathops makes use of that feature.
It is possible to avoid all this by writing a batch file for the inkscape command line to loop through all the paths in the document and apply simplify, but you wouldn't really have the same control as using a selection.
Excellent!. I grabbed that extension and modified it to add a simplify operation. It still seems to be changing the geometry somewhat. I'll delve a bit further.
FYI, the purpose of this is to reduce the number of superfluous nodes in a path as they make my laser cutter freak out.
Where does all these "superfluous" nodes came from? A normal text to path conversion shouldn´t result in such a mess.
I'm just doing a regular object to path operation, but with certain fonts, the resultant path has a lot of superfluous nodes as seen in my screenshot above. This shows the nodes before and after simplification. I suppose it must be something to do with the way some fonts store their glyphs.
Another example of an inefficiently encoded font. This one is "Birds of Paradise".
In the both examples it´s a lousy font developing - mostly happens on cloned fonts - BUT your simplification is great!
Hej Fergal,
Your extension is great news.
Does the extension also get rid of the double nodes (on top of each other)?
After Bolean path operations and also after using the bucket fill tool I see those double nodes everywhere.
Unfortunately not. My extension just calls Path->Simplify which does not join double nodes AFAIK. There's probably another extension that does that, or may some built in function that I don't know about.
https://inkscape.org/~EllenWasbo/★removeduplicatenodes
I tried that extension and it doesn't seem to join double nodes. Tried with Inkscape 1.0.2. Also with Inkscape 1.1 I get a deprecation warning. If I do SHIFT+J on the highlighted double node, it works as expected.
Just found the extension and trusted the author.
No idea how you managed to get those doubles at the corners but selecting with node tool (all at once) and go Join selected nodes don´t merge them?
It turns out I somehow had three duplicates stacked up.
However after deleting the surplus ones, CTRL+A then SHIFT+J, didn't merge any of the double nodes. If I select them individually it does work though. This applies to v1.0.2 & v1.1. I haven't tried on v0.9.2 which is my go to version as it seems to be much more stable than the v1.x releases. I've just been experimenting with the newer versions for the new functionality.
I'm working on an update to the removeduplicatenodes to add more functions. I wrote it for version 1.0 or higher, but have not worked on it for a while so maybe more is becoming depricated now than before. I will look into that. I will also run tests with more than duplicates to make it work for that too. Just have to come up with all options to test...
I'm happy to help test it. Just let me know what you need.
BTW thanks for all the info about stroke fonts you have on your website. When I first got my laser cutter 6 months ago I was on a quest for those kind of fonts, and found your website to be a valuable source of information.
Thanks fergal and Ellen!
Now I finally found some time to work on the removeDuplicateNodes extension - updating it for v1.1 concerning the deprication warning and also finalizing some bugfixes and extra options. So if someone would like to test it ( @fergal ?) the new version can be found here:
https://gitlab.com/EllenWasbo/inkscape-extension-removeduplicatenodes
Hi Ellen
Thanks for the extension update.
I've done some quick testing on it with v1.1 and it works, almost. Not all duplicate nodes are being removed. See screenshots.
Thanks
Fergal
Did you have the interpolate option off? Sometimes there is a little discrepancy within the duplicates and the upper option to interpolate with a discrepancy can be used with a small number to force joining the points. Often this is within the 7th decimal...so interpolating will not do much, just make it happen. Or you could send me the SVG and I'll troubleshoot.
Sorry double post
Here's a screenshot of my settings. I increased the join distance to 0.1 and that helped find the duplicates, so it must be a math rounding error.
I also tried reversing the direction of the top arc segment. This produced unexpected results. I was hoping it would just reverse the direction of that segment so that the path was continuous around the shape. What I'm trying to achieve is to optimize the path for laser cutting so that the laser head moves in one continuous path as much as possible without jumping around or going back on itself. I'd like to get my files as optimal as possible in Inkscape rather than relying on the laser cutter software to do the optimization.
I've also attached the SVG.
When selecting all paths in your file and having the same settings as you I get the expected result (see attached). For the upper object where all paths are combined, the algorithm will evaluate those in relation to each other. For the lower object where there are separate paths nothing happens as the paths are seen one by one. Now the question is why this work differently on my computer compared to yours. I'm on Windows 10, inkscape v1.1. And you?
My versions:
Inkscape 1.1 (c68e22c387, 2021-05-23)
Windows 10.0.18363 Build 18363
There's something strange going on. I reordered the segments so that the one with the reversed path was at the bottom of the stack instead of at the top in the object view, then did Path->Combine, then ran your extension and got this result.
With reversing the top path and moving that to bottom of the stack - I could also reproduce strange results (though not equal to yours). I'll look more into that. I could not replicate the problem with other reverse and reorder. With the "allow for reverse" option selected you should not need to do the reversing yourself. I'll have to troubleshoot.
Now I have tested with a lot more combinations of situations and find no more errors with my tests. You are welcome to test it.
https://gitlab.com/EllenWasbo/inkscape-extension-removeduplicatenodes
Initial tests confirm that your extension is working correctly.
Many thanks for your work on this.
Fergal