Hi everyone,
I have just started using KiCad, and just started to use the Python scripting console.
I’m following along this guide, and have the following code:
import pcbnew;
board = pcbnew.GetBoard();
SCALE = 1000000.0;
boardbbox = board.ComputeBoundingBox();
boardx1 = boardbbox.GetX();
boardy1 = boardbbox.GetY();
boardwidth = boardbbox.GetWidth();
boardheight = boardbbox.GetHeight();
print("Position ({}, {}), width ({}, {})".format(
boardx1, boardy1, boardwidth, boardheight));
I assumed initially that the SCALE
variable was somehow automagically picked up by the KiCad Python interpreter, but the results were printed in the internal KiCad precision:
Position (126974999, 88874999), width (25450002, 25450002)
Is there some convenient way to tell the board object, “Hey, give me all measurements premultiplied by a scale factor”?
Edit: Well, if I’d read a bit further I would have seen the SCALE
get used to divide everything. I could just write a wrapper function anyway.
Edit 2: I’ve just found the function pcbnew.ToMM()
in the API, which appears to do exactly what I want.