Python code for PCB Editor (6.0.7)

Hi does anyone know why code examples seen online are not recognised in the python shell?

I want to write a script that will put a edge cut circles in the place of through vias, so that when the board is exported as step, it will show via sized holes in the place of where the vias were since the vias do not show up on the exported step and it is important for me to know the places of vias.

For example: circle = pcbnew.DRAWSEGMENT() is not recognised in the shell. Neither is it in the doxygen documentation.

Is there any chance of getting a useful documentation instead of the dreaded doxygen generated documentation that tells you nothing about to use it.

Something along the quality of the AutoIt documentation would be nice, i.e Function HotKeySet

I can’t help (don’t know Python at all) but I’m curious why you need to know the places of vias?
Vias typically can be moved to another place when making next PCB revision so associating some mechanical solutions with the position of the vias seems for me strange.

• If you can see/place the Via on PCB, then simply use the Circle tool to draw it around the Via on the Edge_Cut layer. Screenshot

• To enable running script from the Python console, you need to start with a couple of lines prior to adding your Valid code ( Circle code, whatever code that is valid…)

The two lines you need to start with;:

import pcbnew
board = pcbnew.GetBoard();

You might want to use kicadstepup (FreeCad workbench) to import your board. That can get you vias, traces, silkscreen, anything you like, all into your 3d model in FreeCAD, and then you can export STEP with any or all of those elements.

1 Like

to load vias drills you need to set -1 in your preferences kSU tab

1 Like

Some examples for KiCad 6.0 are in the source code repository:

You can also search this forum (use e.g. DRAWSEGMENT).