Python + sewing: Making basic shapes and splitting up larger patterns

Posted: - Modified: | geek, sewing

More Python and sewing. =) The first step was to make parameterization even easier by allowing command-line specification of measurements. I refactored some code from client.py and modified mkpattern to accept the new arguments, splitting up the name and value based on regular expressions (commit). That way, I could quickly generate patterns based on different dimensions, like so:

python ../mkpattern --client=../customer/Sacha/sacha-cm.json \
   --pattern=../patterns/box_tote.py \
   --styles=../tests/test_styles.json \
   -m height=4in -m width=7.5in -m seam_allowance=0.5in \
   -m depth=7.5in -m strap_width=1in -m strap_length=10in -m hem_allowance=1in \
   ../foo.svg

I sketched basic patterns for cylindrical and box-type containers the other day, so I wanted to try them out. It turned out that the Python framework I used for sewing patterns didn’t yet support arcs. Adding the arc element to the SVG was straightforward. I initially faked the bounding box for the arc, but since that made the code misbehave a little, I looked around for a better implementation. I translated the code from this post from 2011 to Python and added it to the code (git commit). That allowed me to make a simple cylinder pattern generator. I haven’t tested it yet, but it looks reasonable.

2015-10-27 20_30_11-foo.svgThe box tote was interesting to work on. When I did the math, I couldn’t believe that the calculations were that simple. I was waiting for a sqrt or a cos to show up, I think. Still, the small-scale paper version I taped up looks like it makes sense, and I’ll sew a full-size version soon. J- asked for a light blue lunch bag that would fit our standard containers, and I’ve been meaning to make a casserole carrier for a while now. It would be handy to be able to make bags that are the right size. Too small and things don’t lie flat, too big and they move around too much.

2015-10-27 20_31_54-foo.svg - Inkscape

I spent most of my time making a flexible circle skirt pattern, pretzeling my brain around circumferences, angles, multiple pieces, and fullness multipliers. I’m happy with the way it turned out. It can generate patterns for quarter-circle skirts, half-circle skirts, full-circle skirts – even an arbitrary fraction of skirt fullness split into an arbitrary number of pieces, with optional seam allowance, waist seam allowance, and hem allowance. If you give it the fabric width, it will split the pattern into however many pieces are needed. If you specify a seam allowance and you want a full-circle skirt in a single piece (maybe for dolls), it’ll leave room for the seam allowances by adjusting the inner radius. We’re heading into snow pants season, so I probably won’t get around to testing it in fabric for a while. Caveat netrix, I guess.

I also got around to writing a tool for splitting up large patterns so that I could print them on a regular printer. I had tried Posterazor and a few other tools for splitting up large images into smaller pages, but I wanted something that would add cutting lines and page numbers. It turns out that all you need to do is change the SVG’s height, width, and viewPort. I added a rectangle for the cutting line and some text for the page numbers. I haven’t figured out how to use pysvg to replace the contents of an existing text element, but since the tool prints out non-overlapping regions, I just keep adding more text elements. My script creates a numbered sequence of SVGs. I haven’t found a convenient way to print multiple SVGs in one go, but I can select multiple PNGs and print those, and I can use Inkscape’s command line to convert SVGs to PNGs like so:

inkscape -z -e output-01.png -d 300 output-01.svg

There’s supposed to be a -p command to output Postscript ready for printing, but command-line printing on Windows doesn’t seem to be as much of a thing as it is on Linux. Something to figure out another time, maybe. Anyway, now that I have a conversion pipeline, I can write a Bash script or Emacs Lisp to process things automatically.

I’ll probably move from all this theoretical script-writing to more hands-on sewing during the rest of the week. My fabric order has arrived, so I’ve got a bit of cutting and sewing ahead of me.

Hmm. With the command-line measurement and scaling overrides, it might be interesting to use this framework for papercraft and laser-cutting too. Someday!

You can comment with Disqus or you can e-mail me at sacha@sachachua.com.