How to find duplicate SVG paths before plotting (and avoid accidental overdraw)

An SVG can look perfectly clean on screen while containing geometry that a pen plotter will draw more than once.

Two identical paths may occupy exactly the same position.

A duplicated group may be hidden behind another object.

Or a vector-editing operation may accidentally leave an extra copy of a line in the document.

Because the duplicate geometry overlaps the original, it may be difficult to notice visually.

But a pen plotter can still execute both paths, potentially retracing the same line and depositing additional ink.

This tutorial explains how to investigate duplicate geometry and introduces a small Python script for detecting one common type of duplication.

1. Understand why duplicates matter

Repeated geometry is not always a problem.

Sometimes artists deliberately retrace lines to produce darker marks or unusual textures.

But accidental duplication can introduce unwanted effects.

Possible consequences include:

  • Longer plotting time.
  • Repeated pen contact over the same geometry.
  • Additional ink accumulation.
  • Increased wear or friction.
  • Unexpected dark areas.
  • More complex path ordering.

The effect depends on the machine, pen, ink and paper.

A duplicate path does not guarantee a visible defect, but it should usually be understood before production.

2. Identify where duplicates come from

Common sources include:

Copy and paste operations

A shape is duplicated and the copy remains directly above the original.

Vector editing

An operation produces a new path without removing its source.

Imported artwork

Different layers may contain identical geometry.

Repeated exports

Geometry may be combined incorrectly when multiple SVG files are assembled.

Generative code

A script may unintentionally emit the same segment more than once.

The best prevention is to inspect the actual plot-ready SVG rather than rely only on its appearance in the editor.

3. A simple SVG example

Consider this file:

<svg xmlns="http://www.w3.org/2000/svg"
     width="100mm"
     height="100mm"
     viewBox="0 0 100 100">

  <g fill="none" stroke="black">
    <path id="line-a" d="M 10 10 L 80 10"/>
    <path id="line-b" d="M 10 10 L 80 10"/>
    <path id="line-c" d="M 10 30 L 80 30"/>
  </g>

</svg>

The first two paths describe exactly the same line.

On screen, the overlap may be difficult to distinguish from a single path.

But both path elements are present in the file.

Depending on the plotting software, both may be sent to the machine.

4. Begin with the vector editor

Before writing code, try a basic manual inspection.

Depending on the editor:

  1. Select a suspicious object.
  2. Temporarily move it away from its position.
  3. Check whether identical geometry remains underneath.
  4. Undo the movement.
  5. Inspect the relevant layer or object list.
  6. Check for duplicated groups or hidden elements.

Do not permanently delete geometry until you understand its purpose.

Some repeated paths may belong to different pen assignments or deliberate layering effects.

5. Detect identical path data with Python

The following script uses only Python’s standard library.

It reads an SVG and looks for path elements that have identical d attributes under the same sequence of SVG transform attributes.

Save it as find-duplicate-paths.py:

from collections import defaultdict
import sys
import xml.etree.ElementTree as ET

if len(sys.argv) != 2:
    raise SystemExit(
        "Usage: python find-duplicate-paths.py drawing.svg"
    )

root = ET.parse(sys.argv[1]).getroot()

seen = defaultdict(list)
counter = 0


def scan(element, transform_chain=()):
    global counter

    transform = element.get("transform")

    if transform:
        transform_chain += (transform,)

    if element.tag.rsplit("}", 1)[-1] == "path":
        counter += 1

        path_data = " ".join(
            element.get("d", "").split()
        )

        if path_data:
            seen[(transform_chain, path_data)].append(
                (
                    counter,
                    element.get("id", "(no id)")
                )
            )

    for child in element:
        scan(child, transform_chain)


scan(root)

groups = [
    items
    for items in seen.values()
    if len(items) > 1
]

print(f"Inspected {counter} path elements")

print(
    f"Found {len(groups)} groups with identical "
    "path data and transform chains"
)

for items in groups:
    print("Potential duplicate:", items)

print("Review visually before deleting anything.")

Run it using:

python find-duplicate-paths.py drawing.svg

Replace drawing.svg with the path to your SVG file.

The script reports potential duplicate groups.

It does not edit or delete anything.

6. Understand the limitations

This is a deliberately simple detector.

It does not perform complete geometric comparison.

Two paths can describe the same physical geometry using different commands.

For example:

<path d="M 10 10 L 80 10"/>
<path d="M 80 10 L 10 10"/>

These paths traverse the same segment in opposite directions.

Their d attributes are different, so the script does not identify them as identical.

Likewise, two paths may use different coordinates combined with different transformations that produce the same final geometry.

The script compares literal transformation chains rather than calculating their resulting matrices.

It also does not inspect SVG shapes such as circles or rectangles, <use> references, clipping effects or every possible rendering rule.

A result of zero potential duplicates does not prove that the SVG contains no overlapping geometry.

7. Treat reported matches as warnings

Suppose the script reports two paths with identical geometry.

Before removing one, inspect:

  • Their assigned layers.
  • Stroke colours.
  • Intended pen assignments.
  • Visibility.
  • Deliberate overlaps.
  • Any relevant plotting-software behaviour.

Two identical paths assigned to different pens might be part of an intentional artistic process.

The script does not attempt to determine artistic intent.

It provides diagnostic information.

8. Distinguish duplicates from intersections

Two paths can cross without being duplicates.

A horizontal line and a vertical line may intersect at one coordinate but represent distinct geometry.

Similarly, two paths can share an endpoint without being duplicates.

These cases should not automatically be removed.

The more difficult cases are partially overlapping segments, reversed paths and complex geometry that is mathematically equivalent despite different SVG instructions.

Those require more advanced geometric analysis.

9. Inspect the plot-ready version

A source SVG may be clean while its exported or processed version contains repeated geometry.

Conversely, an optimisation process may alter the path structure.

For important drawings, inspect the actual file that will be sent to the plotting application.

Plotterfolk’s SVG Preflight Checker can help review SVG features that may require attention.

The simple Python script above provides an additional targeted check for identical path instructions.

Neither should be treated as a complete guarantee against every type of geometric duplication.

10. Avoid destructive automatic cleanup

It may be tempting to automatically delete every reported duplicate.

That can be risky.

The duplicates may belong to separate colour groups or intentionally repeated strokes.

Before changing the file:

  1. Preserve the original.
  2. Review each reported group.
  3. Determine whether the repetition is accidental.
  4. Remove only the unwanted geometry.
  5. Export a new plot-ready version.
  6. Compare the drawing before and after cleanup.
  7. Verify pen assignments and physical dimensions.

Do not overwrite the only copy of the artwork.

The key takeaway

A clean-looking SVG is not necessarily a clean set of plotting paths.

Overlapping geometry can remain invisible in a rendered preview while producing additional physical pen movements.

Exact path-data comparison is a useful first diagnostic step, but it cannot replace geometric inspection or an understanding of the intended drawing.

The safest workflow is to identify potential duplicates, review their purpose and remove only the geometry that is genuinely unintended.