inkstitch / pyembroidery

libembroidery/EmbroideryFormats converted to python
MIT License
71 stars 28 forks source link

Portable Use? #65

Open wwderw opened 5 years ago

wwderw commented 5 years ago

Is the repo able to be used as a standalone without having to traditionally install via PIP etc? If it is, what would be the commands for the various functions by for portable use?

If it isn't as of now, would it be possible to have a portable version?

tatarize commented 5 years ago

The PyPI install to be accessed through PIP is an extra feature that Lex requested. The repo works entirely independently it doesn't need to be installed by PIP you can just download the code and use that in any way you need or see fit. The Pip version doesn't include a few of the utility scripts you'd find in this repo like mass_convert or stitch_entry_pmv. But if you download the code and execute that in python 2 or 3 it'll convert all your designs (from /convert to /results) into the other formats en masse or let you hand entry a .pmv file, or let you write your own embroideries. If you have anything you'd think loading or saving embroideries would be useful for yeah, you can download the code here.

If that's what you mean by standalone then yes, the code is just here, has no requirements or need to be downloaded one way rather than another.

tatarize commented 5 years ago

You would just import the directory and start using it, the readme should give some pretty good explanations for a lot of them.

from pyembroidery import *

convert("this_file.exp", "my_new_file.dst")

pattern = read("my_new_file.dst")
# Do something with pattern.
write(pattern,"this_other_file.u01")
tatarize commented 5 years ago

The pattern classes themselves also have a bunch of hooks to modify the data. You can access the stitches iterate through them, modify them in whatever ways you want, and save them out in whatever format you need. So a bit of script to modify the content of a .u01 file, it wouldn't be too hard to create a little utility to iterate through the various stitches and tell it to add a SLOW command here at stitch 303 and a FAST command here at stitch 402, then save the file out. Or hook it up as a backend to anything else that uses python.

pyembroidery is intended for everybody. Inkstitch is/was just the main emphasis on who everybody is.

If you find some part of the readme documentation lacking or confusing, say something. I don't really know what other people would need it for, so I built it for everything I could think of. But, the documentation might be confusing in places or not explain things well, and those bits would need polish but I won't know where they are because none of it confuses me.

wwderw commented 5 years ago

Well, what I'm trying to do now is a simple conversion. My ultimate goal is export CSV from Ink/Stitch to add in commands that may not be setup in Ink/Stitch right now in a text editor and then output a support file format from that. A little on the tedious side, but it should work. Mainly for sequins (always back to the sequins with me).

I've downloads the zip file from the repo, extracted it to the location that I wanted it.

I'm assuming everything is CLI, so I'm CD'ing into pyembroidery-master/pyembroidery.

I'm trying to figure out the command string in it's entirety. For instance, if I'm going to use libembroidery-convert it would be after CD'ing to the location that the portable binary is in:

./libembroidery-convert /path/to/file/input.dst /path/to/file/output.csv

Or something along those lines. What would by the pyembroidery equivalent to that? Where would I need to CD into and the command string that I would use? Especially if it's different from what the command is if it's directly installed into the system.

tatarize commented 5 years ago

Hm. That's likely quite doable. But, it's mostly setup for scripting just now. I could certainly make that script it's like two lines. Though I've not messed with taking CLI data into a python script yet.

tatarize commented 5 years ago

Pretty easy, lemme code that up.

tatarize commented 5 years ago

Okay, added pyembroidery-convert.py. If you have python installed properly you can actually just drag a current embroidery on it, and it'll export the csv file even without command line interfacing. You just drag a file there, and get a csv. But, in CLI you can give it the output format too which can be .u01 or .exp or whatever you need.

wwderw commented 5 years ago

That appears to work with the test file for conversion that I had setup.

Awesome!

Thanks.

tatarize commented 5 years ago

@wwderw Since I know it might come up. I also added a CSV reader to pyembroidery a second ago. So you will be able to convert to CSV then find a line you care about, and add FAST and SLOW

So export to CSV, change stuff a bit like:

"*","25","STITCH","-53","-66","20","18"
"*","26","STITCH","-16","-33","37","33"
"*","26","SLOW"
"*","27","STITCH","21","0","37","33"
"*","28","STITCH","50","26","29","26"
"*","29","STITCH","45","20","-5","-6"
"*","30","STITCH","15","-19","-30","-39"
"*","31","STITCH","-16","-58","-31","-39"
"*","32","STITCH","-47","-98","-31","-40"
"*","33","STITCH","-35","-87","12","11"
"*","34","STITCH","2","-54","37","33"
"*","26","FAST"
"*","35","STITCH","39","-21","37","33"
"*","36","STITCH","74","10","35","31"

Then convert that to .U01 and it'll have the fast and slow commands properly added.

It should also work for Embroidermodder but I've not seen their CSV files kicking around but I only tweaked the thread to make them more readable and so I added a catch for that in the reader.

wwderw commented 5 years ago

Awesome. That will definitely come in handy.

Thank you!

tatarize commented 5 years ago

If I manage to get the teaching .u01 files working, I might even be able to have you export .u01 and edit in both sequins and slows and fasts into the same file. But, that's a bit off the beaten path. Converting from sequins to .u01 will, currently, convert the sequins to jump stitches. Then you could edit them on the machine. But, it should certainly work standalone and let you edit the CSV now. I could also make a quick script to convert from CSV to all your standard chosen embroidery formats.

Maybe you'd have some need to drop a file on the converter, get a csv, edit the csv and drop the csv on an exporter, and make the file types you usually export.

tatarize commented 5 years ago

Added the exporter. So if you drag a file of any format pyembroidery reads onto that script, even a modified .csv you'll get the standard file types you deal.

They will be largely raw reads and writes so if there's some issue like dsts not producing trims explicitly and some other format exporting oddly it's due to that and the script could be tweaked to add some stablizing code to convert some number of jumps to a trim, etc.

But you could drop a file on the converter, and it will default convert it to .csv then edit that .csv to add SLOW and FAST then drag the edited .csv on the exporter and boom... .u01 with fast and slow commands.

wwderw commented 5 years ago

Maybe you'd have some need to drop a file on the converter, get a csv, edit the csv and drop the csv on an exporter, and make the file types you usually export.

Yes, I could do definitely come up with some use cases where that would come in handy.

I do get a fair amount of people that want me to edit already purchased designs to tweak them to get what they exactly did and this would come in handy for that.

Added the exporter. So if you drag a file of any format pyembroidery reads onto that script, even a modified .csv you'll get the standard file types you deal.

Awesome, I'll be looking forward to trying that out.

tatarize commented 5 years ago

Well, I already pushed it to main here, so you could try it now. It's really just a couple of lines of code in a file. Little utilities that do things like that are pretty trivial, given how everything is put together.

wwderw commented 5 years ago

It definitely exports all the main files.

One thing that I noticed, it appears that the source file in question has to be in the same directory as the py file in order for it to work. It doesn't look like you can name a file outside that directory that has the py file being used.

Otherwise, everything works as it should. That's pretty cool.

tatarize commented 5 years ago

There are clearly ways to fix that, basically you need to setup python to have the directory the script occupies set in the python path.

https://chrisyeh96.github.io/2017/08/08/definitive-guide-python-imports.html#basics-of-the-python-import-and-syspath

Basically what's happening is the scripts I gave there have an import, "from pyembroidery import *" this means it needs to know what pyembroidery is and how to find it. There's a few ways to give it this information so it'll find it even without your python scripts in the main directory there.

https://stackoverflow.com/questions/3701646/how-to-add-to-the-pythonpath-in-windows

tatarize commented 5 years ago

Added this to my windows variables. Which points to my python27 directory and the pycharm project. Then moved the script and a relevant file to my desktop and dragged the embroidery and dropped it on the script and it executed and created the csv file.

pythonpath