Edge_Cuts Python Bindings KiCad 7

I am trying to create a plugin to create a PCB, I managed to draw in the layers, however, I cannot figure out how to do it in the Edge Cuts. I am using KiCAD 7.0 so maybe that’s the reason. I have tried to look into the pcbnew documentation but I couldn’t find any examples.
This is the code I have right now:

            # create the edge cuts
            for edge_cut in coil["edgeCuts"]:
                edge = pcbnew.PCB_SHAPE(board)
                edge.SetShape(pcbnew.SHAPE_T_POLY)
                edge.SetFilled(False)
                edge.SetLayer(pcbnew.Edge_Cuts)
                edge.SetWidth(int(0.1 * pcbnew.FromMM(1)))
                v = []
                for point in edge_cut:
                    x = int(point["x"]) + CENTER_X
                    y = int(point["y"]) + CENTER_Y
                    v.append(pcbnew.VECTOR2I(x, y))

                edge.SetPolyPoints(v)
                board.Add(edge)

It doesn’t give any error, however nothing appears in the Edge Cuts layer in KiCAD.

I have tried this too:

                # create the edge cuts
                for edge_cut in coil["edgeCuts"]:
                    edge = pcbnew.DRAWSEGMENT(board)
                    edge.SetShape(pcbnew.S_SEGMENT)
                    edge.SetLayer(pcbnew.Edge_Cuts)
                    edge.SetWidth(int(0.1 * pcbnew.FromMM(1)))
                    v = []
                    for point in edge_cut:
                        x = int(point["x"]) + CENTER_X
                        y = int(point["y"]) + CENTER_Y
                        v.append(pcbnew.wxPoint(x, y))
                    edge.SetStart(v[0])
                    for point in v[1:]:
                        edge.SetEnd(point)
                        board.Add(edge)
                        edge = pcbnew.DRAWSEGMENT(board)
                        edge.SetShape(pcbnew.S_SEGMENT)
                        edge.SetLayer(pcbnew.Edge_Cuts)
                        edge.SetWidth(int(0.1 * pcbnew.FromMM(1)))
                        edge.SetStart(point)
                    edge.SetEnd(v[0])  # close the polygon
                    board.Add(edge)

And same issue, no errors but nothing appears in KiCAD.

Your coordinates likely need to be converted to internal units (FromMM()) and unless your code is in a plugin you need to do pcbnew.Refresh() at the end.

1 Like

Thanks! You were right, the issue was that I was not converting it to internal units.

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