[SOLVED]Python script experiments-Internal VS GUI measurements

I’m playing about with python scripting (invoked using execfile(‘C:/Users/David/Desktop/Kicad_python_scripts/basics.py’)
This particular script states the following

#####################

physical dimensions

#####################

coordinate space of kicad_pcb is in mm. At the beginning of

https://en.wikibooks.org/wiki/Kicad/file_formats#Board_File_Format

“All physical units are in mils (1/1000th inch) unless otherwise noted.”

then later in historical notes, it says,

As of 2013, the PCBnew application creates “.kicad_pcb” files that begin with

“(kicad_pcb (version 3)”. All distances are in millimetres.

the internal coordinate space of pcbnew is 10E-6 mm. (a millionth of a mm)

the coordinate 121550000 corresponds to 121.550000

SCALE = 1000000.0

boardbbox = board.ComputeBoundingBox()
boardxl = boardbbox.GetX()
boardyl = boardbbox.GetY()
boardwidth = boardbbox.GetWidth()
boardheight = boardbbox.GetHeight()

print(“this board is at position {}, {} {} wide and {} high”.format(boardxl,
boardyl,
boardwidth,
boardheight))

The script reports that the board size is 66502281 wide and 51943363 high (66.5 mm wide by 51.9 mm high). However, when I measure the board using the vernier tool in PCBnew the size is 64.21 mm by 49.2 mm.
There is a difference of over 2 mm in the measurements. I wonder why that is and which measurement is the more accurate? Any clues? Thanks.

David.

Speaking from the top of my head, the bounding box might include also other items (text, drawings on user layers, …). Do you have anything (text, drawings, …) outside of the board edge?

The simplest explanation would be that both are correct, but you used the measurement ruler wrong. It can snap to PCB outlines, but only to the endpoints of lines.
Are you also sure the PCB is rectangular?

Also, the .kicad_pcb is human readable ascii and the format is describet at the KiCad website. It should not be hard to find the board outline with a text editor.

Board outlines are treated as (sort of) tracks, and have a width, which is used for calculating clearances. Maybe this width is also added calculating the bounding box. (I’m guessing here).

I’ve just noticed a couple of labels on the front silkscreen layer that are outside of the board edges. They account for the difference in measurements. I wonder if it’s possible to exclude certain layers using the scripts? Anyway, mystery solved. Thanks.

David.

You can iterate through all drawings and find those on edge.cuts layer. Then you can build a bounding box containing all of these items.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.