I recentIy published an Inkscape extension to remove duplicate nodes that is useful when preparing designs for my cutting machine. Sometimes there might be duplicate line segments. This might be problematic as the cutter will trace that path twize and might mess up the product or, if used as a plotter, spill the ink. Others have provided Inkscape extensions to remove duplicate lines, but so far I’ve not found any that accept a user defined tolerance for the matching of segments allowing for inaccuracies f.x. with snapping. So I wanted to give it a try and write that extension.
(Scroll down to bottom of this post to find the download links).
What the extension does
The extension compare all line segments (between nodes). All four control points of the cubic bezier curves are compared after converting the paths to cubic super path. Identical line segments will always be removed, that is when all four control points are the exact same independent of direction (a reversed match is also a match). There are three additional options to select:
- Include searching for matching segments where one continuous path is overlapping itself.
- Adding a tolerance to allow for some discrepancies and still regard it a match. What looks like a exact match will often be slightly different when regarding all decimals. Using snapping will most often cause some discrepancy.
- Optionally interpolate the remaining line segment with the removed line segment.
NB: If the tolerance is larger than the length of the some line segments and the option to include matches where a path is overlapping itself might cause finding a match between neighboring small segments.
NB2: Interpolation might cause a rough or slight deformation compared to the original paths. This is because the average of each pair of controlpoints replace the original controlpoints i.e. a simple approximation.
NB3: The extension ignores grouped paths. Ungroup first (you will get a warning).
NB4: All shape elements have to be converted to path, else they will be ignored (you will get a warning).
A hexagon pattern can easily be created in Inkscape drawing hexagons and then snapping these shapes together. Cutting or plotting this paths will cause all but the outer edges to cut or plot twize. For better visualize how the extension operates I will let the hexagons have some distance and I will leave the original path in pink with a duplicate in black on top to show the original and the result for comparison.
The next example is the same as above with an interpolation between the matches before removing the match.
From stickfont to single line font
I’ve been working quite a lot with single line fonts. TTF and OTF fonts can only contain closed paths. A stickfont have closed paths and zero with and might look like a single line font. The problem with the stickfonts is that each glyph have a duplication.
I tried the remove duplicate lines extension with my own stickfonts and the Cambam stickfonts to remove the duplication. For my own stickfonts I had to explored different methods for creating them and have now found that OTF font type is optimal for this. The OTF font format keep the cubic Bèzier splines better than the TTF font (conversion to quadratic splines). The Cambam stickfonts are TTF, but have a lot of nodes so the conversion is simple (little curvature pr line segment) and do not change. So the remove duplicate lines extension will work also for the Cambam stickfonts (though be a bit slow due to the excessive number of nodes).
How to convert from stickfont to single line font in Inkscape:
- create your text using a stickfont (one with good match between the line segments, like my OTF stickfonts)
- use text on path if you like
- Object to path (Shift + Ctrl + C)
- Ungroup (Shift + Ctrl + G)
- Extensions – Cutlings – Remove Duplicate Lines … – Apply
- Validate the results (use Preferences setting Tools->Node->Show path direction to see small red half-arrows visualizing the direction in edit node mode)
Text to path and ungroup
Now look at the paths in edit node mode. I have the Preferences setting Tools-Node-Show path direction so the small red arrows show in the image below that we have path in both directions. Also the gray diamond node indicators lack the black frame indicating that there are nodes on top of each other.
Appøy remove duplicate lines to convert the stickfont to single line font
Now apply the remove duplicate lines extension selecting the option to compare each path against itself and with a small tolarance as there is slight differences due to precision from the ttF font or the convert text to path conversion.
Jigsaw from outlines to cutlines
I downloaded this jigsaw svg file from Wikipedia. Each puzzle piece is a closed path. If you want to cut that jigsaw with a cutter, each path will be traced twize. This is either unnecessary or might destroy the edges. I’ve used removeDuplicateLines to remove the overlapping line segments, just to show an example of what this extension can do.
Then I havecombined the paths (Ctrl+K) and used the removeDuplicateNodes extension to join the splitted paths – just for fun and to show some options:
How to download the extension
- Go to my Inkscape Resources and download the zip file (arrow down button)
- or if you have an GitLab account you could download from here.
- The zip file containing the files removeDuplicateLines .inx and .py
- Unzip and place the files in your User extensions folder. (Check Inkscape Preferences (Shift+Ctrl+P) and find your local User extensions folder specified in the System tab).
- Restart Inkscape to update with the new extensions. You will find these in menu Extensions > Cutlings > Remove duplicate lines…
How to use the extension
Select the paths for which you want to clean up duplicate lines. Select Extensions > Cutlings > Remove duplicate lines… Set your selections and tolerance. Apply (or Live preview to watch what will happen while playing with the settings).
14 thoughts on “Remove duplicate lines”
What version of Inkscape is the best to run this extension? I cannot get it going in 1.0.
Thanks in advance for your reply and many thanks for the good work!
I’m sorry to hear that you cannot make it work with version 1.0. I have implemented it with version 1.1 and tested it with version 1.0.2 too (all Windows). I hope you will make it work – if not please tell me.
Thank you for creating this inkscape plugin. It was exactly what I needed (and works perfectly in Inkscape 1.2).
I have been trying to find an acceptable workflow for plotting wireframes of 3D models using my cnc machine.
I can now do so by exporting the model wireframes from Blender with the addon – “Viewport to SVG” and removing the overlapping lines in Inkscape with your Remove duplicate lines extension (all opensource!).
You have saved me the pain of (attempting!) to code this myself.
Thank you so much! I’m very happy.
It makes me happy to hear that this extension made you happy 🙂 You’re very welcome!
Hi, thank you for making this, amazing tool! It works when I try it on the puzzle svg, but when I try it on my own file, it removes the entire image – do you know why this is? Tolerance set to 0.
Many thanks 🙂
Oh – no. That certainly is not supposed to happen. I have not had a look at the code for quite a while, so I cannot from the top of my head come up with a reason for such a behaviour. You are welcome to send me your file and I’ll take a look at it (or just parts of the svg if the same happens for just parts and you would like to keep the design for yourself). ellen(at)wasbo.net
Thank you so much for the extension. I have been looking for this for a long time to help with laser cutting.
You’re very welcome 🙂 I guess I should try to make it easier to find, then. I have started the process of refreshing the code so that I can try to merge it into the official version of Inkscape. That might make it easier to find.
thanks, really useful plugin! thanks for your work.
However the plugin doesn’t erase overlapping paths if both of their nodes don’t coincide, is there a way to make this happen? For example if two squares side by side share only part of their edge?
Well, anything is possible, and I see your point, but that would require quite another algorithm. Currently I am not planning to implement that.
Ok, I understand, anyway your plugin will save me a lot of time, so thank you again.