Skip to content

freesewing/pattern-via-io

Repository files navigation

Example of a STDIN → FreeSewing → STDOUT pipeline

This repository was setup to answer this question (paraphrased):

I am a Python dev. How can I use FreeSewing when I have a bunch of settings and all I want is an SVG?

To use FreeSewing in a different environment, there are various technical solutions, but the simplest approach is to push your settings as JSON to the stdin of a NodeJS script that will then read the settings from stdin, parse them as JSON, generate the pattern, and then dump the resulting SVG to stdout.

This repo holds an example of how to do that (in src/index.mjs) and some further instructions below.

Getting started

To try this at home, you will need NodeJS on your system. Assuming you do, you can clone this repository, cd into it, and install dependencies.

git clone git@github.com:freesewing/pattern-via-io.git
cd pattern-via-io
npm install

Once the dependencies are installed you can run this to try it:

cat example-settings.json | node generate-pattern.mjs

Or to save it to a file:

cat example-settings.json | node generate-pattern.mjs > pattern.svg

You can find the pattern.svg generated by the example above in this repository.

Using a different design

This example uses @freesewing/aaron which extends @freesewing/brian. If you want to use a different design (for example simon) you should install it:

npm i --save @freesewing/simon@next

And then change the import in the script.

Note: The @next suffix is required until v3 is in GA.

Accessing pattern data, rather then generating an SVG

If you want to interact with the resulting pattern in programmatic way -- rather than just get the SVG -- you can run this:

cat example-settings.json | node generate-json.mjs

It will dump (by default) the parts as JSON, which contain all parts with their points and paths. However, you can access any pattern data by adapting the generate-json.mjs example.

The relevant lines are:

const data = pattern.getRenderProps()
console.log(JSON.stringify(data.parts, null, 2))

Questions?

Join us on Discord at discord.freesewing.org.

About

An example of a stdin -> freesewing -> stdout pipeline

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published