Skip to main content

A package to help you convert a SVG file to a 3D STL file

Project description

svg2stl

This repository provides a script which takes as input an SVG such as this one:

example.svg

It outputs an STL file like this:

example.png

You can also see an interactive version here.

The resulting solid is a cuboid with holes in it. It essentially adds a third dimension to the SVG file. The purpose of the output STL is to be fed into a 3D printer. The end goal is to make a physical stencil for artistic purposes.

Installation

git clone https://github.com/MaxHalford/svg2stl
cd svg2stl
pip install -r requirements.txt

Usage

You can generate an STL with the same name as the input file like this:

python svg2stl.py example.svg --thickness 4

The thickness is the distance between the solid's bottom and top.

An SVG is a sequence of geometric lines. When these lines are not straight, then points are interpolated along their trajectory. You can choose how many points to interpolate as so:

python svg2stl.py example.svg --definition 12

In addition to saving the result, you can show what the rendered solid looks like in a GUI:

python svg2stl.py example.svg --thickness 4 --show

Some SVGs have bogus instructions at the beginning of their path definition. For instance, the first shape of example_bogus.svg is bogus and cause the rendering to fail. Skipping it does the trick:

python svg2stl.py example_bogus.svg --skip 1

How it works

  • The SVG file is parsed into a sequence of steps thanks to svg.path.
  • Each step is turned into 2D geometric coordinates by sampling from each step's parametric equation with numpy.
  • Each coordinate is duplicated so that there are top and bottom coordinates.
  • The coordinates are stitched together to define panes: a floor, a ceiling, and many walls.
  • pygmsh does the heavy lifting. It generates a mesh of triangles from the panes through constrained Delaunay triangulation.

Motivation

There are some websites out there that already do this. Like this, this, and this. But they're websites, and sometimes it's nice to be able to do this from the command line. Especially if you want to process many SVGs.

License

The MIT License (MIT). Please see the license file for more information.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

svg2stl-0.0.2.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

svg2stl-0.0.2-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file svg2stl-0.0.2.tar.gz.

File metadata

  • Download URL: svg2stl-0.0.2.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.10

File hashes

Hashes for svg2stl-0.0.2.tar.gz
Algorithm Hash digest
SHA256 c606b5706334cb09fc6469baaa503c8dfdb04acec1dec7ed43afab1fce750ab2
MD5 f3a55b2e30eadab62dd06974a82ef78d
BLAKE2b-256 124bc7e04e88fc0a431482f305cfdacc77a1f5de5e7de03add30d15916d71bdd

See more details on using hashes here.

File details

Details for the file svg2stl-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: svg2stl-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.10

File hashes

Hashes for svg2stl-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f1601e51d01937f360538f3a8d84fc0959165cefe784856354aa28a6ff089928
MD5 9446410c98073da1ffc891870120da41
BLAKE2b-256 3a79319704e652f6e83911554d984a2f6e0282642b9ebb50b565c25199cef97a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page