11

My SVG has multiple line objects forming a closed shape. I must convert this into a single path, so that a laser cutting machine just follows the path to cut the shape from the material without jump.

Of course this can be manually done with inkscape by:

  1. Converting all individual objects into one path, resulting in a single path but two overlapping nodes at each angle of the shape
  2. For each angle, select both nodes that share the same coordinates and Join selected nodes (Shift+J)

However it requires to perform step 2) thousands of times (once per angle), is there an option to merge all overlapping nodes automatically?

Even if in my case, coordinates of overlapping nodes perfectly match, since there is no perfect equality between floats, eventually a distance could be provided to research overlapping nodes, e.g. all nodes n1, n2 for which distance(n1, n2) ≤ 1e-6 mm (or in pixels) are merged into a single node.

Conflicts start to happen if there are more than 2 nodes within this tolerence, however the Join selected nodes (Shift+J) tool itself seems not to handle this case and only merge two nodes.

This option might also be useful to duplicate a single shape several times on a board, and prevent the laser from cutting a same edge several times damaging the material. But it seems more advanced because there are several paths.

Here is an example of input file:

<svg
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:cc="http://creativecommons.org/ns#"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg"
   version="1.1" id="svg5169"
   viewBox="0 0 20.302442 20.250575"
   height="5.7151623mm"
   width="5.7298002mm">
  <g
     transform="translate(-41.214011,-1123.8181)"
     id="layer1">
    <g
       transform="matrix(0.99667782,0,0,0.99980745,-163.30415,1035.5366)"
       id="g4" />
    <path
       id="line134"
       d="m 41.339286,1123.9953 20,0"
       style="stroke:#191919;stroke-width:0.35433069;stroke-miterlimit:4;stroke-dasharray:none" />
    <path
       id="line138"
       d="m 41.339286,1123.9434 20,20"
       style="stroke:#191919;stroke-width:0.35433072;stroke-miterlimit:4;stroke-dasharray:none" />
    <path
       id="line142"
       d="m 61.339287,1143.8181 0,-20"
       style="stroke:#191919;stroke-width:0.35433072;stroke-miterlimit:4;stroke-dasharray:none" />
  </g>
</svg>

And the output I need to produce to send to the laser-cutting machine, i.e. the same object with a single path:

<svg
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:cc="http://creativecommons.org/ns#"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg"
   version="1.1" id="svg5169"
   viewBox="0 0 20.604885 20.60488"
   height="5.815155mm"
   width="5.8151565mm">
  <g
     transform="translate(-84.099911,-1123.8181)"
     id="layer1">
    <g
       transform="matrix(0.99667782,0,0,0.99980745,-163.30415,1035.5366)"
       id="g4" />
    <path
       id="line142-9"
       d="m 104.52763,1123.9953 -20.000004,0 20.000004,20 z"
       style="fill:none;stroke:#191919;stroke-width:0.35433072;stroke-miterlimit:4;stroke-dasharray:none" />
  </g>
</svg>
2
  • Can you show the image or a significant part of it? Aug 24, 2016 at 18:40
  • 1
    Done! SVG samples added in the original question @user-unknown :)
    – myoan
    Aug 28, 2016 at 14:41

1 Answer 1

13

Referring to the provided source, you need to:

  1. ungroup (Shift-Ctrl-G) your object, select the paths and combine (Ctrl-K) them in a single path
  2. switch in Edit paths by nodes mode (F2), select all the nodes and join selected nodes (Shift-J).

nodes joined

When all the nodes are selected, the join selected nodes function applies to all the couples of endnodes found.

If the coordinates of your nodes overlaps perfectly, this should work (you don't need to repeat your step 2. thousands of times).

In case the coordinates of the nodes doesn't overlap, Inkscape joins the nodes but you can obtain unexpected behaviors, e.g.:

odd results

So, the use of the join on all the nodes should be used with a bit of carefulness.

1
  • 3
    "If the coordinates of your nodes overlaps perfectly, this should work", not clear about what will be done. It seems it won't merge the overlapping nodes but create a null length segment between them. If this is the case, then it won't answer the question but is an acceptable workaround in many cases. Inkscape which is quite poor in editing capabilities is actually missing a "Merge Overlapping Nodes" tool with a variable threshold to merge points not exactly overlapping, a tool found in other graphic applications (not in Illustrator but e.g. in Blender)
    – mins
    Feb 10, 2020 at 15:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.