Skip to main content

Convert an SVG file to a KiCad footprint.

Project description

svg2mod

Build Status GitHub last commit

PyPI - License PyPI - Python Version PyPI

This is a program / library to convert SVG drawings to KiCad footprint module files.

It includes a modified version of cjlano's python SVG parser and drawing module to interpret drawings and approximate curves using straight line segments. Module files can be output in KiCad's legacy or s-expression (i.e., pretty) formats.

Requirements

Python 3

Installation

pip install svg2mod

Example

svg2mod -i input.svg

Usage

usage: svg2mod [-h] [-i FILENAME] [-o FILENAME] [-c] [-P] [-v] [--debug] [-x]
               [-d DPI] [-f FACTOR] [-p PRECISION] [--format FORMAT]
               [--name NAME] [--units UNITS] [--value VALUE] [-F DEFAULT_FONT]
               [-l]

Convert Inkscape SVG drawings to KiCad footprint modules.

optional arguments:
  -h, --help            show this help message and exit
  -i FILENAME, --input-file FILENAME
                        Name of the SVG file
  -o FILENAME, --output-file FILENAME
                        Name of the module file
  -c, --center          Center the module to the center of the bounding box
  -P, --convert-pads    Convert any artwork on Cu layers to pads
  -v, --verbose         Print more verbose messages
  --debug               Print debug level messages
  -x, --exclude-hidden  Do not export hidden layers
  -d DPI, --dpi DPI     DPI of the SVG file (int)
  -f FACTOR, --factor FACTOR
                        Scale paths by this factor
  -p PRECISION, --precision PRECISION
                        Smoothness for approximating curves with line
                        segments. Input is the approximate length for each
                        line segment in SVG pixels (float)
  --format FORMAT       Output module file format (legacy|pretty)
  --name NAME, --module-name NAME
                        Base name of the module
  --units UNITS         Output units, if output format is legacy (decimal|mm)
  --value VALUE, --module-value VALUE
                        Value of the module
  -F DEFAULT_FONT, --default-font DEFAULT_FONT
                        Default font to use if the target font in a text
                        element cannot be found
  -l, --list-fonts      List all fonts that can be found in common locations```

SVG Files

svg2mod expects images saved in the uncompressed Inkscape SVG (i.e., not "plain SVG") format. This is so it can associate inkscape layers with kicad layers

  • Drawings should be to scale (1 mm in Inscape will be 1 mm in KiCad). Use the --factor option to resize the resulting module(s) up or down from there.
  • Paths are fully supported Rect are partially supported.
    • A path may have an outline and a fill. (Colors will be ignored.)
    • A path may have holes, defined by interior segments within the path (see included examples).
    • 100% Transparent fills and strokes with be ignored.
    • Rect supports rotations, but not corner radii.
    • Text Elements are partially supported
  • Groups may be used. However, styles applied to groups (e.g., stroke-width) are not applied to contained drawing elements. In these cases, it may be necessary to ungroup (and perhaps regroup) the elements.
  • Layers must be named to match the target in kicad. The supported layers are listed below. They will be ignored otherwise.
  • If there is an issue parsing an inkscape object or stroke convert it to a path.
    • Use Inkscape's "Path->Object To Path" and "Path->Stroke To Path" menu options to convert these elements into paths that will work.

Layers

This supports the layers listed below. They are the same in inkscape and kicad:

KiCad layer(s) KiCad legacy KiCad pretty
F.Cu Yes Yes
B.Cu Yes Yes
F.Adhes Yes Yes
B.Adhes Yes Yes
F.Paste Yes Yes
B.Paste Yes Yes
F.SilkS Yes Yes
B.SilkS Yes Yes
F.Mask Yes Yes
B.Mask Yes Yes
Dwgs.User Yes Yes
Cmts.User Yes Yes
Eco1.User Yes Yes
Eco2.User Yes Yes
Edge.Cuts Yes Yes
F.Fab -- Yes
B.Fab -- Yes
F.CrtYd -- Yes
B.CrtYd -- Yes

Note: If you have a layer "F.Cu", all of its sub-layers will be treated as "F.Cu" regardless of their names.

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

svg2mod-0.1.6.2.tar.gz (42.7 kB view details)

Uploaded Source

Built Distribution

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

svg2mod-0.1.6.2-py3-none-any.whl (42.8 kB view details)

Uploaded Python 3

File details

Details for the file svg2mod-0.1.6.2.tar.gz.

File metadata

  • Download URL: svg2mod-0.1.6.2.tar.gz
  • Upload date:
  • Size: 42.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.6.7

File hashes

Hashes for svg2mod-0.1.6.2.tar.gz
Algorithm Hash digest
SHA256 98d8d0b5b6fe1654ae1b1a6a3441052ea15cd39692da8722ea28226a30abc264
MD5 e56e9d83bb116fa850960fa8279b8175
BLAKE2b-256 de27201ecd778b58a9e02fcf5014ddb5b2151868130eca4066adb996509af8e9

See more details on using hashes here.

File details

Details for the file svg2mod-0.1.6.2-py3-none-any.whl.

File metadata

  • Download URL: svg2mod-0.1.6.2-py3-none-any.whl
  • Upload date:
  • Size: 42.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.6.7

File hashes

Hashes for svg2mod-0.1.6.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1a68b2c0aa7b6ee925a22146d48decbfafed2ddf5762239d671866711ddb4917
MD5 dd27426f140d282e5930c71b49b795e2
BLAKE2b-256 1db35fd52a23c50dce22fb845d4e894665bc3d62fa10465849fb5b2f7cee5e31

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