Remove duplicate lines

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

The dialog box for the extension and the options available to remove duplicate line segements.

Examples

Hexagon pattern

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.

Here a tolerance have been applied. The resulting black paths is lacking where the pink original is visible. The first path is the hexacon where all sides remain, removing a segment of the two hexagons above it. The next path is the upper right hexagon, finding and removing a match in the next and central hexagon. And finally the central hexagon find another match to remove from the last path, the upeer left hexagon.

The next example is the same as above with an interpolation between the matches before removing the match.

Interpolating control points of the removed and remaining line segment. I’m not ure if this will be useful, but I just could not resist trying to make the option available.

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

Here I have written a text with the Cambam Stick8 font, object 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.

The Cambam stickfont converted to path, ungrouped and shown in edit node mode. All line segments are duplicated and reversed.

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.

Here after applying the removeDuplicateLines-extension the paths have only one direction. The reversed path is removed and the stickfont is converted to single line paths. Remember to use the option to compare each path against itself and add a small tolerance. I used 0,1 but it will depend on the font size and your unit setting.

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.

Before and after removing duplicate lines for a part of the jigsaw. The dark lines showing an overlap disappear.

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

20 thoughts on “Remove duplicate lines

  1. Hi Ellen,
    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!
    Regards, Arnold

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

  2. Hi Ellen,
    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.
    Ian

  3. 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 🙂
    Erin

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

  4. Thank you so much for the extension. I have been looking for this for a long time to help with laser cutting.

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

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

    1. Well, anything is possible, and I see your point, but that would require quite another algorithm. Currently I am not planning to implement that.

  6. Ok, I understand, anyway your plugin will save me a lot of time, so thank you again.

  7. When I install the plugin, I see in the menu “Extensions -> Cutlings -> {completely blank stub menu}” as if the name of the extension isn’t registering in the menu. So I can’t even begin to use it!

    1. Oops! I wasn’t using the latest version of Inkscape! (0.92 -> 1.3 … makes a huge difference!!)
      Thanks, it works awesomely! Looking forward to laser cutting my puzzle!

      1. Yes, there were some major changes for extensions turning version 1+. Glad you figured it out. Good luck with the puzzle!

  8. Hi, I also want to say thank you for being able to help the makers with this annoying problem.

    Please tell me if this extension should work with Inkscape 1.3, Mac OSX. After I ran the extensions, my objects broke up and moved up into a horizontal cluster.

    Many thanks.

    1. Oh – now – sad to hear that your objects went messy. I will try to get access to a Mac and run the tests and come back to you if it is a general issue with an easy fix or less so. No promises of how quickly I’ll do that – busy days…

      1. Ellen,
        Thank you for the reply. I believe I discovered why the extension did not work in my situation. Inkscape uses the top-left origin by default. The bottom left point, however, was set up as the origin (x:0, y:0). This origin position is more convenient because we place our drawing tool on the wall. Please take your time.

Leave a Reply

Your email address will not be published. Required fields are marked *