Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
f1f736c
Mark the footprint as virtual in the pretty format
matthijskooijman Jun 22, 2017
75d59f2
Update svg2mod.py to work with python3 methods
zirafa May 9, 2018
a028e41
Updates svg.py to work with python3
zirafa May 9, 2018
57e62df
Update README.md
zirafa May 9, 2018
231ecdd
Update README.md
zirafa May 9, 2018
32977b8
Update README.md
zirafa May 9, 2018
ac6714b
Update README.md
zirafa May 16, 2018
ecfcabe
Update .gitignore to block more files and initial changes to svg2mod
NaH012 Aug 13, 2018
576f3b7
Update legacy to support layers and update readme
NaH012 Aug 13, 2018
fad7bc3
Added centering as an option and remove front only option
NaH012 Aug 13, 2018
8b912e1
Fix README.md
NaH012 Aug 14, 2018
c879207
Remove null flags
NaH012 Aug 14, 2018
7337745
Add more options for pretty format
NaH012 Aug 14, 2018
8115775
Update README.md
NaH012 Aug 23, 2018
fae2216
Changed the model attribute to virtual
NaH012 Aug 23, 2018
5a6b18b
Fix closepath per https://github.com/cjlano/svg/pull/12
markrages Feb 15, 2019
7305ca5
Merge branch 'export-as-virtual' of https://github.com/matthijskooijm…
terje Feb 28, 2020
d9f0211
Merge branch 'matthijskooijman-export-as-virtual'
terje Feb 28, 2020
5de0727
Update .gitignore to block more files and initial changes to svg2mod
NaH012 Aug 13, 2018
389af93
Update legacy to support layers and update readme
NaH012 Aug 13, 2018
da01c78
Added centering as an option and remove front only option
NaH012 Aug 13, 2018
5fc8d98
Fix README.md
NaH012 Aug 14, 2018
78a2857
Remove null flags
NaH012 Aug 14, 2018
93b978c
Add more options for pretty format
NaH012 Aug 14, 2018
0f40b47
Update README.md
NaH012 Aug 23, 2018
bd72004
Merge branch 'master' of https://github.com/zirafa/svg2mod into ziraf…
terje Feb 28, 2020
ebfd086
Merge branch 'zirafa-master'
terje Feb 28, 2020
0c4627a
Do not close non-filled polygons
marcan Dec 1, 2018
c162c8e
Fix stroke-width calculation for non-px units
marcan Dec 3, 2018
3b41684
Remove empty style values
terje Feb 28, 2020
36853c9
Merge terje/svg2mod into master
Sodium-Hydrogen Mar 10, 2020
f5aedbf
Merge branch 'master' of https://github.com/terje/svg2mod into terje-…
Sodium-Hydrogen Mar 10, 2020
25b9611
Merge branch 'terje-master'
Sodium-Hydrogen Mar 10, 2020
29f3d63
Update pip instructions
Sodium-Hydrogen Mar 10, 2020
a98b694
travis ci testing
Sodium-Hydrogen Mar 10, 2020
cd2616d
Add a sample test
Sodium-Hydrogen Mar 10, 2020
b9d5690
Better test
Sodium-Hydrogen Mar 10, 2020
4b4ea89
Update Readme.md
Sodium-Hydrogen Mar 10, 2020
2ef7007
Merge branch 'render-o-properly' of https://github.com/markrages/svg2…
Sodium-Hydrogen Mar 10, 2020
c1d9bdd
Merge branch 'markrages-render-o-properly'
Sodium-Hydrogen Mar 10, 2020
151cd9f
Fix problem when merging
Sodium-Hydrogen Mar 10, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
*~
.*.sw?
*.pyc
build
dist
svg2mod.egg-info
*.kicad_mod
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
language: python
script: pip3 install ./ && svg2mod -i examples/dt-logo.svg -o output.kicad_mod --name TEST --value VALUE -f 2 -p 1 --format pretty --units mm -d 300 --center
63 changes: 42 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
# svg2mod
This is a small program to convert Inkscape SVG drawings to KiCad footprint module files. It uses [cjlano's python SVG parser and drawing module](https://github.com/cjlano/svg) 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. Horizontally mirrored modules are automatically generated for use on the back of a 2-layer PCB.
[![Build Status](https://travis-ci.org/Sodium-Hydrogen/svg2mod.svg?branch=master)](https://travis-ci.org/Sodium-Hydrogen/svg2mod)

This is a small program to convert Inkscape SVG drawings to KiCad footprint module files. It uses [cjlano's python SVG parser and drawing module](https://github.com/cjlano/svg) 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

```pip3 install git+https://github.com/Sodium-Hydrogen/svg2mod```

If building fails make sure setuptools is up to date. `pip3 install setuptools --upgrade`

## Example

```svg2mod -i input.svg -p 1.0```

## Usage
```
usage: svg2mod.py [-h] -i FILENAME [-o FILENAME] [--name NAME] [--value VALUE]
[-f FACTOR] [-p PRECISION] [-d DPI] [--front-only] [--format FORMAT]
[--units UNITS]
usage: svg2mod [-h] -i FILENAME [-o FILENAME] [--name NAME] [--value VALUE]
[-f FACTOR] [-p PRECISION] [--format FORMAT] [--units UNITS]
[-d DPI] [--center]

Convert Inkscape SVG drawings to KiCad footprint modules.

Expand All @@ -24,10 +40,10 @@ optional arguments:
-p PRECISION, --precision PRECISION
smoothness for approximating curves with line segments
(float)
-d DPI, --dpi DPI DPI of the SVG file (int)
--front-only omit output of back module (legacy output format)
--format FORMAT output module file format (legacy|pretty)
--units UNITS output units, if output format is legacy (decimil|mm)
-d DPI, --dpi DPI DPI of the SVG file (int)
--center Center the module to the center of the bounding box
```

## SVG Files
Expand All @@ -39,9 +55,7 @@ svg2mod expects images saved in the uncompressed Inkscape SVG (i.e., not "plain
* A path may have holes, defined by interior segments within the path (see included examples). Sometimes this will render propery in KiCad, but sometimes not.
* Paths with filled areas within holes may not work at all.
* 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 used to indicate the mapping of drawing elements to KiCad layers.
* Layers must be named according to the rules below.
* Drawing elements will be mapped to front layers by default. Mirrored images of these elements can be automatically generated and mapped to back layers in a separate module (see --front-only option).
* Layers must be named according to the rules below.
* Other types of elements such as rect, arc, and circle are not supported.
* Use Inkscape's "Path->Object To Path" and "Path->Stroke To Path" menu options to convert these elements into paths that will work.

Expand All @@ -50,17 +64,24 @@ Layers must be named (case-insensitive) according to the following rules:

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

Note: If you have a layer "Cu", all of its sub-layers will be treated as "Cu" regardless of their names.
Note: If you have a layer "F.Cu", all of its sub-layers will be treated as "F.Cu" regardless of their names.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
version='0.1.0',
description="Convert an SVG file to a KiCad footprint.",
long_description=readme,
author='https://github.com/mtl',
author='https://github.com/Sodium-Hydrogen',
author_email='',
url='https://github.com/mtl/svg2mod',
url='https://github.com/Sodium-Hydrogen/svg2mod',
packages=setuptools.find_packages(),
entry_points={'console_scripts':['svg2mod = svg2mod.svg2mod:main']},
package_dir={'svg2mod':'svg2mod'},
Expand Down
8 changes: 3 additions & 5 deletions svg2mod/svg/svg/svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,10 @@ class Group(Transformable):

def __init__(self, elt=None):
Transformable.__init__(self, elt)

self.name = ""
if elt is not None:

for id, value in elt.attrib.iteritems():
for id, value in elt.attrib.items():

id = self.parse_name( id )
if id[ "name" ] == "label":
Expand Down Expand Up @@ -401,7 +400,7 @@ def parse(self, pathstr):
# Close Path
l = Segment(current_pt, start_pt)
self.items.append(l)

current_pt = start_pt

elif command in 'LHV':
# LineTo, Horizontal & Vertical line
Expand Down Expand Up @@ -708,4 +707,3 @@ def default(self, obj):
tag = getattr(cls, 'tag', None)
if tag:
svgClass[svg_ns + tag] = cls

Loading