realthunder / fcad_pcb

FreeCAD scripts for PCB CAD/CAM
MIT License
129 stars 24 forks source link

FreeCAD scripts for PCB CAD/CAM & FEM

fcad_pcb is yet another way to improve ECAD/MCAD collaboration between FreeCAD and KiCAD.

The original purpose of these tools was to do PCB milling in FreeCAD. It can do much more now.:

Installation

The fcad_pcb macro is written in Python and requires FreeCAD 0.17 or later to work properly.

  1. Clone this repo into your freecad macro directory. To check what the default path of your macro directory is go to dropdown Macro > Macros.. and find the path in the field User macros location
    cd <path/to/your/macros/directory>
    git clone https://github.com/realthunder/fcad_pcb/
  2. Enter the locally cloned repository
    cd fcad_pcb/
  3. Download the repository submodules
    git submodule update --init --recursive
  4. Restart FreeCAD

Usage

At this time fcad is usable through the FreeCAD python console.

Generating copper layers

from fcad_pcb import kicad
pcb = kicad.KicadFcad(<full_path_to_your_kicad_pcb_file>)
pcb.makeCoppers()

Note: the file path syntax should be one of the following:

  pcb = kicad.KicadFcad('C:/Users/fooDesktop/MyProject/MyPCBfilekicad_pcb')

Alternatively if you don't want to replace backslashes for a Windows system:

  pcb = kicad.KicadFcad(r'C:\Users\foo\Desktop\MyProject\MyPCBfile.kicad_pcb')`

Generating copper layers / pads / drills + ready for FEM workbench

Generate these full solid objects ready to for the FEM workbench

  from fcad_pcb import kicad
  pcb = kicad.KicadFcad(<full_path_to_your_kicad_pcb_file>)
  pcb.make(copper_thickness=0.035, board_thickness=1.53, combo=False, fuseCoppers=True )
  #
  # NOTE: KiCAD 5.99 and later added possibility to specify per layer thickness including
  #       dielectric layers. You are no longer required to explicitly supply thickness
  #       parameters in any of the function calls as shown above.

Supply copper thickness per layer, pass a dictionary instead.

Use either integer or layer name

Generating a single copper layer

pcb.setLayer('F.Cu')
pcb.makeCopper()

Filtering by net name

For local nets you have to specify full hierarchical name

  pcb.setNetFilter('GND')
  pcb.makeCopper()

  pcb.setNetFilter('GND','VCC')
  pcb.makeCopper()

Shape without intermediate document objects

In case you only want the shape without any intermediate document objects

  from fcad_pcb import kicad
  pcb = kicad.KicadFcad(<full_path_to_your_kicad_pcb_file>, add_feature=False)

  # Or, you can set the parameter later
  pcb.add_feature = False

  # All the above makeXXX() calls now returns a shape without creating any features
  # For example, if you want the complete fused copper layers.
  # Note: 'thickness' can be a dictionary for per layer thickness
  coppers = pcb.makeCoppers(shape_type='solid', holes=True, fuse=True)
  Part.show(coppers)

Note: that there is a sample board to play with inside this repo: test.kicad_pcb

Screenshots

FEM of tracks and drills

Full Board Loaded in FC for FEM

Full PCB in FreeCAD

Full PCB in FreeCAD

PCB for milling

PCB for milling

FEM of tracks and drills

Full Board Loaded in FC for FEM

Requirements

FreeCAD >= v0.17