Getting the area of the board (python scripting)

I’d like to know the area surrounded by the Edge.Cuts layer. Any hints to get this result using the scripting console?

Don’t hijack the thread, ask in separate thread.

On getting the area inside edge cuts. This reply is probably too late for you, but… Perhaps for others.

How pcbnew graphics are represented probably warrants its own post. My dxf stuff generates some graphics but I haven’t talked about how to go the other way. They’re all stored in board.GetDrawings() and can be lines, circles and arcs. Lines and circles are intuitive, but arcs are a little weird.[1]

you want something like this:

import pcbnew
board = pcbnew.GetBoard()
for d in board.GetDrawings():
   if (d.GetLayerName() == 'Edge.Cuts'):
>>> bnds
[<pcbnew.DRAWSEGMENT; proxy of <Swig Object of type 'DRAWSEGMENT *' at 0x7faf38a55e40> >, <pcbnew.DRAWSEGMENT; proxy of <Swig Object of type 'DRAWSEGMENT *' at 0x7faf38a55de0> >, <pcbnew.DRAWSEGMENT; proxy of <Swig Object of type 'DRAWSEGMENT *' at 0x7faf38a55e70> >, <pcbnew.DRAWSEGMENT; proxy of <Swig Object of type 'DRAWSEGMENT *' at 0x7faf38a55060> >]

b = bnds[0]
>>> wxPoint(123952000, 59182000)

from there, it’s just math. Take the area under each line. Since some of the lines go the other way, they’ll have negative area under them. It’s also how to check if something is a hole. Negative overall area.[2]

[1] for more about arcs, you might get some ideas from this file of mine. The function dxfarc2pcbarc. Probably not the helpful though.

[2] for more on areas and holes. See this file. The function is poly_is_hole. Likely more helpful than footnote #1.

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