Inkscape.org
Creating New Extensions Extension to call Path->Simplify
  1. #1
    fergal fergal @fergal

    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

  2. #2
    inklinea inklinea @inklinea⛰️

    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.

     

  3. #3
    fergal fergal @fergal

    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.

    Capture
  4. #4
    Polygon Polygon @Polygon🌶

    Where does all these "superfluous" nodes came from? A normal text to path conversion shouldn´t result in such a mess.

  5. #5
    fergal fergal @fergal

    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.

  6. #6
    fergal fergal @fergal

    Another example of an inefficiently encoded font. This one is "Birds of Paradise".

    Capture2
  7. #7
    Polygon Polygon @Polygon🌶

    In the both examples it´s a lousy font developing - mostly happens on cloned fonts - BUT your simplification is great!

     

  8. #8
    Kirstie Kirstie @Kirstie🌷

    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.

  9. #9
    fergal fergal @fergal

    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.

  10. #10
    Polygon Polygon @Polygon🌶

    https://inkscape.org/~EllenWasbo/★removeduplicatenodes

  11. #11
    fergal fergal @fergal

    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.

    Duplicatenodes
  12. #12
    Polygon Polygon @Polygon🌶
    *

    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?

  13. #13
    fergal fergal @fergal

    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.

  14. #14
    Ellen Wasbø Ellen Wasbø @EllenWasbo

    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...

  15. #15
    fergal fergal @fergal
    *

    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.

  16. #16
    Kirstie Kirstie @Kirstie🌷

    Thanks fergal and Ellen!
     

  17. #17
    Ellen Wasbø Ellen Wasbø @EllenWasbo

    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

     

  18. #18
    fergal fergal @fergal

    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

    Screenshot 2
    Screenshot 1
  19. #19
    Ellen Wasbø Ellen Wasbø @EllenWasbo

    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.

  20. #20
    Ellen Wasbø Ellen Wasbø @EllenWasbo
    *

    Sorry double post

  21. #21
    fergal fergal @fergal

    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.

    Screenshot 2021 08 09 141430
    Screenshot 2021 08 09 141307
    Removeduplicatenodestest
  22. #22
    Ellen Wasbø Ellen Wasbø @EllenWasbo

    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?

    Removeduplicatenodestest Output
  23. #23
    fergal fergal @fergal

    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.

    Screenshot 2021 08 09 170958
  24. #24
    Ellen Wasbø Ellen Wasbø @EllenWasbo

    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.

  25. #25
    Ellen Wasbø Ellen Wasbø @EllenWasbo

    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

  26. #26
    fergal fergal @fergal

    Initial tests confirm that your extension is working correctly.

    Many thanks for your work on this.

    Fergal