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

It outputs an [STL file](https://www.wikiwand.com/en/STL_(file_format)) like this:

You can also see an interactive version [here](tests/example.stl).
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](https://www.wikiwand.com/en/Stencil) for artistic purposes.
## Installation
```sh
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:
```sh
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:
```sh
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:
```sh
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](tests/example_bogus.svg) is bogus and cause the rendering to fail. Skipping it does the trick:
```sh
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`](https://github.com/regebro/svg.path).
- Each step is turned into 2D geometric coordinates by sampling from each step's parametric equation with [`numpy`](https://numpy.org/).
- 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`](https://github.com/nschloe/pygmsh) does the heavy lifting. It generates a mesh of triangles from the panes through [constrained Delaunay triangulation](https://www.wikiwand.com/en/Constrained_Delaunay_triangulation).
## Motivation
There are some websites out there that already do this. Like [this](https://svg2stl.com/), [this](https://activmap.github.io/svg-to-stl/), and [this](https://github.com/rcalme/svg-to-stl). 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](LICENSE) for more information.
Raw data
{
"_id": null,
"home_page": null,
"name": "svg2stl-aviinfinity",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "stl, svg, svg2stl, 3d",
"author": null,
"author_email": "aviinfinity <pi@aviparshan.com>",
"download_url": "https://files.pythonhosted.org/packages/77/03/03bc7f4092941e45e943f2aa80f1f6088c6536f5727a3263759b6d779643/svg2stl_aviinfinity-0.0.2.tar.gz",
"platform": null,
"description": "# svg2stl\r\n\r\nThis repository provides a script which takes as input an SVG such as this one:\r\n\r\n\r\n\r\nIt outputs an [STL file](https://www.wikiwand.com/en/STL_(file_format)) like this:\r\n\r\n\r\n\r\nYou can also see an interactive version [here](tests/example.stl).\r\n\r\nThe 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](https://www.wikiwand.com/en/Stencil) for artistic purposes.\r\n\r\n## Installation\r\n\r\n```sh\r\ngit clone https://github.com/MaxHalford/svg2stl\r\ncd svg2stl\r\npip install -r requirements.txt\r\n```\r\n\r\n## Usage\r\n\r\nYou can generate an STL with the same name as the input file like this:\r\n\r\n```sh\r\npython svg2stl.py example.svg --thickness 4\r\n```\r\n\r\nThe thickness is the distance between the solid's bottom and top.\r\n\r\nAn 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:\r\n\r\n```sh\r\npython svg2stl.py example.svg --definition 12\r\n```\r\n\r\nIn addition to saving the result, you can show what the rendered solid looks like in a GUI:\r\n\r\n```sh\r\npython svg2stl.py example.svg --thickness 4 --show\r\n```\r\n\r\nSome SVGs have bogus instructions at the beginning of their path definition. For instance, the first shape of [example_bogus.svg](tests/example_bogus.svg) is bogus and cause the rendering to fail. Skipping it does the trick:\r\n\r\n```sh\r\npython svg2stl.py example_bogus.svg --skip 1\r\n```\r\n\r\n## How it works\r\n\r\n- The SVG file is parsed into a sequence of steps thanks to [`svg.path`](https://github.com/regebro/svg.path).\r\n- Each step is turned into 2D geometric coordinates by sampling from each step's parametric equation with [`numpy`](https://numpy.org/).\r\n- Each coordinate is duplicated so that there are top and bottom coordinates.\r\n- The coordinates are stitched together to define panes: a floor, a ceiling, and many walls.\r\n- [`pygmsh`](https://github.com/nschloe/pygmsh) does the heavy lifting. It generates a mesh of triangles from the panes through [constrained Delaunay triangulation](https://www.wikiwand.com/en/Constrained_Delaunay_triangulation).\r\n\r\n## Motivation\r\n\r\nThere are some websites out there that already do this. Like [this](https://svg2stl.com/), [this](https://activmap.github.io/svg-to-stl/), and [this](https://github.com/rcalme/svg-to-stl). 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.\r\n\r\n## License\r\n\r\nThe MIT License (MIT). Please see the [license file](LICENSE) for more information.\r\n",
"bugtrack_url": null,
"license": null,
"summary": "A package to help you convert a SVG file to a 3D STL file",
"version": "0.0.2",
"project_urls": {
"Homepage": "https://github.com/avipars/svg2stl",
"Issues": "https://github.com/avipars/svg2stl/issues"
},
"split_keywords": [
"stl",
" svg",
" svg2stl",
" 3d"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "db1994ae327c7594a9c6f006d792a9f52765b02d5cd6274ab0ca93937e2f92d7",
"md5": "4c608836d7874e55d1116c17847679b1",
"sha256": "46c21205c0b24d36314e6086bd9a95bc55ad63b9af43d6ffbb0231be8fbca99e"
},
"downloads": -1,
"filename": "svg2stl_aviinfinity-0.0.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "4c608836d7874e55d1116c17847679b1",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 4261,
"upload_time": "2025-09-03T08:36:53",
"upload_time_iso_8601": "2025-09-03T08:36:53.151799Z",
"url": "https://files.pythonhosted.org/packages/db/19/94ae327c7594a9c6f006d792a9f52765b02d5cd6274ab0ca93937e2f92d7/svg2stl_aviinfinity-0.0.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "770303bc7f4092941e45e943f2aa80f1f6088c6536f5727a3263759b6d779643",
"md5": "3dd848e852345c16afb32a5960dc2967",
"sha256": "5ba403c3725695e7b4042846ab097b3ced588dbf2acf8d573ccf2d4c38004092"
},
"downloads": -1,
"filename": "svg2stl_aviinfinity-0.0.2.tar.gz",
"has_sig": false,
"md5_digest": "3dd848e852345c16afb32a5960dc2967",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 4120,
"upload_time": "2025-09-03T08:36:54",
"upload_time_iso_8601": "2025-09-03T08:36:54.629737Z",
"url": "https://files.pythonhosted.org/packages/77/03/03bc7f4092941e45e943f2aa80f1f6088c6536f5727a3263759b6d779643/svg2stl_aviinfinity-0.0.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-09-03 08:36:54",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "avipars",
"github_project": "svg2stl",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "gmsh",
"specs": [
[
"==",
"4.9.1"
]
]
},
{
"name": "numpy",
"specs": [
[
"==",
"1.19.5"
]
]
},
{
"name": "svg.path",
"specs": [
[
"==",
"5.0.0a1"
]
]
}
],
"lcname": "svg2stl-aviinfinity"
}