Automated pattern drafting

When I learned pattern drafting (drawing ‘templates’ for cutting/sewing garments) I quickly realized that it was just an algorithm for drawing a shape. You take the measurements of the person it’s supposed to fit. Then using those and some rules of thumb that are based on common sense and (I suppose) centuries of experience with what human bodies tend to look like you can draw a sewing pattern that will fit that person. This means that of course it can be automated.

There can be lots of ifs and buts and decision making, for example: if the sleeve comes out too smal, adjust here and there. Those decisions are usually made based on experience/convention and insight into what makes a pattern fit, but there is no reason that they can’t also be translated into a decision tree in your code. It’s just a matter of how detailed you want to make it.

Of course when you are making bespoke or one-of-a-kind items there is no real point in automating every detail of the pattern since you will only use it once. But a lot of custom patterns are made by starting with a basic pattern that is then altered. So automating the basics might actually be worthwhile.

The idea

I’d turned that idea over in my mind a few times but I wasn’t entirely sure where to start, drawing straight lines was probably straightforward enough, but how to deal with curves (do I have to learn a bunch of math to program them?) and things like ‘draw this at a right angle to this other line’? So I never really got around to it. But a few months ago I was looking through some .svg images for a CTF and spent some time learning how they work. An SVG (‘Scalable Vector Graphics’) image is a vector-based image, i.e. it’s not made up of a grid of pixels in which each pixel is assigned a certain color, but rather of a set of descriptions like ‘make a line from here to there’ that is therefore infinitely scalable/zoomable without looking pixelated. It turns out that the SVG format supports all kinds of shapes, lines, and also curves that can be defined based on coordinates within the image. Basically it was perfect for my pattern drafting idea.

So today I sat down to make a proof-of-concept automated pattern of a really basic straight skirt. The goal was to learn about some SVG specifics, and to hopefully write re-usable code snippets that could help me do more complicated things in the future. This is what I’m trying to re-create (taken from the pattern drafting instructions I’m used to):

Drawing a square

But before I started I wanted to make sure I got the idea of using python to define a bunch of coordinates, and then translating them to an SVG file. (There is a writesvg library for python, but I decided not to use it because the extra layer of abstraction of using that library’s functions made it harder for me to understand what I was doing. Maybe later.) So started out trying to draw a square.

The very first proof-of-concept / hello world script is this one:

class Point:
	def __init__(self, coords):
		self.x = coords[0]
		self.y = coords[1]
	def moveup(self,amount):
		self.y = self.y - amount
	def movedown(self,amount):
		self.y = self.y + amount
	def moveleft(self,amount):
		self.x = self.x - amount
	def moveright(self,amount):
		self.x = self.x + amount
	def coords(self):
		return [self.x,self.y]

def makepathstring(points):
	first = True
	output = ""
	for point in points:
		if first == True:
			first = False
			output += "M%d,%d " % (point.x,point.y)
			output += "%d,%d " % (point.x,point.y)
	return output
a = Point(20,20)
b = Point(20,80)
c = Point(80,80)
d = Point(80,20)
dimensions = [100,100]

outfile = open("box.svg", "w")
std_header = '<svg xmlns="" width="%d" height ="%d">\n' % (dimensions[0],dimensions[1])
std_footer = '\n</svg>'

path = makepathstring([a,b,c,d])
outfile.write('<path d="' + path + '" stroke="black" stroke-width="1"/>')
The glorious result

Proof of concept

So far so good, so I started implementing the pattern drafting instructions. I found that implementing points as a separate class was pretty useful and intuitive, but that making a function to arrange a series of points into an SVG ‘path’ was not great because I needed to be more flexible than that to add curves where I want them etc.

I ended up writing some helper functions that determine the middle of a line or that can create a point on another line at a given distance from either end, as well as a function for creating darts. When I had all the coordinates of my points I quickly generated an image showing those points as dots to check if I was on the right track. Turns out I screwed up my math here and there (working in millimeters instead of centimeters tripped me up multiple times) but it was fairly easy to make it look about right:

I hope you can start to see the shape from the first picture here

Time to connect the dots then!

Thanks to some excellent documentation I learned that you can make curves by giving the start and end points, and then one or two additional points that the the curve is drawn ‘towards’. Basically these additional points determine the initial angle at which the curved line leaves its end point. That’s perfect, because I want most of my curves to either connect smoothly to a nearby straight line (departing angle: straight ahead) or to finish at a 90 degree angle on a corner (departing angle: straight across). This informed at least part of where these anchor points should go. The rest I just messed with a bit until it looked about right.

Then I also did the back of the skirt, and added an indication for the hipline. All in all I think it looks reasonably like the original.


You can download the python script here.

To Do list for later:

  • Make input dynamic (I currently just have some hardcoded example measurements)
  • Change the darts function to support angles rather than just ‘up’ and ‘down’. Strictly speaking that dart in the front should angle slightly towards the side seam, which it currently does not.
  • Add the bit that changes from 1 to 2 darts in the back if the measurements indicate a curvy figure.
  • Do more work on drawing at a specific angle from another line. Probably once I make something that handles that nicely I can also use it for the darts issue above.
  • Then move on to doing more complex patterns like a torso block or even a corset.

2 thoughts on “Automated pattern drafting”

  1. Hi there! Ended up here after drifting over to your blog post-CoCoVid-livestream-corset-workshop-watching (which was fantastic, by the way, thank you!). Just wanted to put it out there that I have an input-based python code to create the classic historical/disney/lolita bell-shaped hoop skirts for any combo of height+waist measurement+desired opulence, because that sort of math is something I (weirdly?) enjoy poring over. Since I shamelessly copied your code above for the automated skirt, it seemed only fair to offer the hoop skirt pattern in exchange. Let me know if you’d like a copy. (aside: I’ve been meaning to get it online for anyone to use, in a GUI, but that level of programming is currently far beyond me.)

    1. Sorry for the awkwardly late reply, really cool that I’m not the only one nerding out over this. Best bet for GUI would probably be to implement the same thing but in javascript so you can dynamically generate and replace the pattern as people adjust the measurements. It seems that there are some SVG-manipulation js libraries out there. I’ll put it on the endless to-do list 😀

Comments are closed.