Python IU Units to MM

Hey All,

Working on a script to export directly from PCBNEW the position of each pad on a board.

Originally I was just swapping all the pads with THT versions, then exporting the drill files, then converting that to the needed format externally, but wanted to try and export directly from KiCad.

I can get the pads via this code:

for pad in pcbnew.GetBoard().GetPads():
    print( str(pad.GetX()) + "/" +  str(pad.GetY()) )

But I’ve been struggling all day to find how to convert IU to MM.

MM to IU I can do via the pcbnew.wxPointMM class, but I can’t seem to find the reverse function.

I thought I had found the way with

pad.GetX() / pcbnew.EDA_IU_SCALE.IU_PER_MM,

but get

TypeError: unsupported operand type(s) for /: 'int' and 'property'

error with this.

Any help appreciated.

No same issue, the pad.GetX() returns an int fine, but can’t seem to get the value from pcbnew.EDA_IU_SCALE.IU_PER_MM

pcbnew.pcbIUScale.IUTomm(<iuValue>) or pcbnew.pcbIUScale.IUTomm(pad.GetX())

Or use pcbnew.PCB_IU_PER_MM

1 Like

yes! thank you!

This is working below now.

for pad in pcbnew.GetBoard().GetPads():
    print( str(pcbnew.pcbIUScale.IUTomm(pad.GetX())) + " " +  str(pcbnew.pcbIUScale.IUTomm(pad.GetY()) ))

By the way, because the python bindings reveal the internal API which is unstable (volatile) between major versions, it’s especially important to give version information when asking about the python API.

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