# Buggy code
def write_embroidery_file(file_path, stitch_plan, svg):
    origin = get_origin(svg)

    pattern = pyembroidery.EmbPattern()

    for color_block in stitch_plan:
        pattern.add_thread(color_block.color.pyembroidery_thread)

        for stitch in color_block:
            if stitch.stop:
                jump_to_stop_point(pattern, svg)
            command = get_command(stitch)
            pattern.add_stitch_absolute(command, stitch.x, stitch.y)

    pattern.add_stitch_absolute(pyembroidery.END, stitch.x, stitch.y)

    # convert from pixels to millimeters
    # also multiply by 10 to get tenths of a millimeter as required by pyembroidery
    scale = 10 / PIXELS_PER_MM

    settings = {
        # correct for the origin
        "translate": -origin,
        # convert from pixels to millimeters
        # also multiply by 10 to get tenths of a millimeter as required by pyembroidery
        "scale": (scale, scale),
        # This forces a jump at the start of the design and after each trim,
        # even if we're close enough not to need one.
        "full_jump": True,
    }

    pyembroidery.write(pattern, file_path, settings)


# Traceback (IOError)
Traceback (most recent call last):

File "inkstitch.py", line 24, in <module>

binary_name = script_name

File "inkscape-0.92.3\share\extensions\inkex.py", line 283, in affect

File "lib\extensions\embroider.py", line 85, in effect

File "lib\output.py", line 114, in write_embroidery_file

File "site-packages\pyembroidery\PyEmbroidery.py", line 593, in write

File "site-packages\pyembroidery\PyEmbroidery.py", line 541, in write_embroidery

IOError: [Errno 2] No such file or directory: 'C:\\Users\\%USERNAME%\\Documents\\Embroidery\\Quik Massage Logo - Embroidery.pes'

# Fixed code
def write_embroidery_file(file_path, stitch_plan, svg):
    origin = get_origin(svg)

    pattern = pyembroidery.EmbPattern()

    for color_block in stitch_plan:
        pattern.add_thread(color_block.color.pyembroidery_thread)

        for stitch in color_block:
            if stitch.stop:
                jump_to_stop_point(pattern, svg)
            command = get_command(stitch)
            pattern.add_stitch_absolute(command, stitch.x, stitch.y)

    pattern.add_stitch_absolute(pyembroidery.END, stitch.x, stitch.y)

    # convert from pixels to millimeters
    # also multiply by 10 to get tenths of a millimeter as required by pyembroidery
    scale = 10 / PIXELS_PER_MM

    settings = {
        # correct for the origin
        "translate": -origin,
        # convert from pixels to millimeters
        # also multiply by 10 to get tenths of a millimeter as required by pyembroidery
        "scale": (scale, scale),
        # This forces a jump at the start of the design and after each trim,
        # even if we're close enough not to need one.
        "full_jump": True,
    }

    try:
        pyembroidery.write(pattern, file_path, settings)
    except IOError as e:
        # L10N low-level file error.  %(error)s is (hopefully?) translated by
        # the user's system automatically.
        (
            print >> sys.stderr,
            _("Error writing to %(path)s: %(error)s")
            % dict(path=file_path, error=e.message),
        )
        sys.exit(1)