EmbroidePy / pyembroidery

pyembroidery library for reading and writing a variety of embroidery formats.
MIT License
181 stars 33 forks source link

I'm unable to write jump stitches without trims in PES format #156

Open talljosh opened 1 year ago

talljosh commented 1 year ago

I have an EverSewn machine which in theory can trim the thread, but in practice, doing so often results in bird nests that jam the machine.

I wrote a small script that uses pyembroidery to duplicate an EmbPattern but filters out any TRIM commands.

The issue I'm facing is that the PES/PEC exporter seems to ignore TRIM commands, and just trim on every JUMP. In PecWriter.py:

        elif data == JUMP:
            jumping = True
            if init:
                write_jump(f, dx, dy)
            else:
                write_trimjump(f, dx, dy)

        …

        elif data == TRIM:
            pass

(I initially thought I was having the same issue with the JEF file format, but it turns out the TRIMs were being added by the JEF importer not the exporter, and I was able to avoid that with the trim_distance setting.)

tatarize commented 1 year ago

The PES/PEC I think has some flag there. But, it seemed like flagging it trimjump was fairly correct. The trim command itself doesn't have an analog. Only trimjump. I could totally tweak it to allow an option of suppressing that and just writing pure jumps each time. Really I'm not entirely sure of the providence of flag for jump without flagging the trim. Libembroidery had most of this info, and copying other writers and parsing through that data seems to suggest that that is how the data should be written.

I'm more than happy to add in some options if it'll let you tweak around this problem. My best suggestion would be to likely just go ahead and tweak the script and delete the if init: and else: write trimjump bits. That avoid writing the flag. I called the flag there trimjump because that's what libembroidery called it, but wrote it out like that consistently because some writers like Wilcom probably did writing like that.

Trims have always been iffy. Most machines don't have them and when they do they often interpolate them and try to figure out where to put them. So there's a solid chance it's your machine adding them and it might be hard to suppress them, and this might not actually do anything. But, if this fixes any problem you have I'm more than happy add that in as a version or an option to the PES writer. The JEF format doesn't really write trims either, or at least has it's own oddities there.

talljosh commented 1 year ago

Ok, I've found a setting on my machine that turns off auto thread trimming on long stitches. So now I just want to make sure that the input file doesn't instruct my machine to trim in other places.

Are you saying that the "trimjump" flag may not actually signal a trim, it might just be a naming convention?

I've updated my local code to this:

    # init = True
    jumping = True

    …
    for stitch in stitches:
        …

        elif data == JUMP:
            jumping = True
            if not trimming:
                write_jump(f, dx, dy)
            else:
                write_trimjump(f, dx, dy)

        …
        elif data == TRIM:
            trimming = True
            continue

        …
        trimming = False

It's probably overkill for what I want, but that way I can insert TRIM commands if I choose to.

I guess an option for this may be helpful. But perhaps I should do a few test PES files first with and without the trimjumps and see what my machine does with them.