bobc / dxf2kicad_mod

Create KiCad footprints and PCBs from DXF files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

dxf2kicad

Create a KiCad footprint or PCB from a DXF file

For example, from

a dxf file

generate a footprint:

footprint sample

How it works

It will read the DXF file and:

  • converts arcs to lines
  • find arcs and lines which compose a closed-loop graphic and output a polygon
  • lines which do not form a closed polygon are output as lines

Layers

Each layer is handled seperately, the layer name is converted to a layer name in the KiCad file.

By default, entities on all layers are written to KiCad layer "F.Cu", and entities identified as polygons will be filled with a solid fill. Entities that form non-closed polylines are output as lines (v5) or polylines (v6) depending on KiCad version.

PCB generation

dxf2kicad can also generate a KiCad PCB (.kicad_pcb) using the --pcb option.

Units

By default, dxf2kicad assumes the DXF file is specified in mm. KiCad output files are always mm. The input units can be set by the following methods in order of priority:

  • command line option -u
  • settings file layer value
  • settings file global value

Valid units are :

  • mm
  • mil
  • inch

Settings File

A settings file may be specified with the -s option, to give finer control over conversion. A settings file is a JSON file. The -w option may be used to create a template file containing defaults.

Default settings file:

{
    "units": "mm",
    "layers": [
        {
            "source_layer": "0",
            "dest_layer": "F.Cu",
            "type": "filled",
            "units": "",
            "offset_x": 0,
            "offset_y": 0
        }
    ],
    "distance_error": 0.025,
    "min_line_width": 0.15,
    "kicad_version": "5",
    "horiz_align": "left",
    "vert_align": "bottom"
}
  • units units of DXF file

dxf_merge

dxf_merge is a utility to extract/copy/merge DXF files. For example, if you have a DXF file for each layer, they can be merged into one DXF file for input to dxf2kicad.

Samples

See tests for some footprint examples.

test_pcb contains a PCB example.

Limitations

  • Supports LINE, ARC, ELLIPSE, POLYLINE, LWPOLYLINE, HATCH, INSERT
  • CIRCLE on a drill layer will create a hole (plated through hole)
  • each line must connect with another line or arc's beginning or end point to within 0.025mm
  • if there are multiple lines with overlapping end points, the algorithm may fail to identify polygons correctly

How to use

Install Python 3.9

See https://www.python.org/downloads/.

Install ezdxf

> pip install ezdxf

Get a copy of dxf2kicad

> git clone https://github.com/bobc/dxf2kicad_mod.git
> cd dxf2kicad_mod

Create a DXF file

Use your favorite CAD to tool to create a DXF file

Generate KiCad footprint

Use following command line to generate footprint

> python dxf2kicad_mod.py <dxf_file_name> <footprint_file.kicad_mod>

Add to KiCad

Add the folder containing the footprint to KiCad's Footprint Library Table.

About

Create KiCad footprints and PCBs from DXF files

License:GNU General Public License v3.0


Languages

Language:Python 99.5%Language:Batchfile 0.5%