Problem with KiCommand copying copper to solder mask

I tried this in 5.1.9 and it doesn’t seem to work. KiCommand says

3 operands left on the stack.

Any hints?

KiCad v6 has “Create from Selection” in the context menu, but for some reason it doesn’t have track → graphics conversion.

You may get the wanted result with this short python script.


import pcbnew
board = pcbnew.GetBoard()
tracksegments = [t for t in board.GetTracks() if (t.GetClass() == 'PCB_TRACK' and t.IsSelected())]
for s in tracksegments:
    line = pcbnew.PCB_SHAPE()
    line.SetShape(pcbnew.S_SEGMENT)
    line.SetLayer(pcbnew.F_Mask)
    line.SetWidth(s.GetWidth() + 50000)
    line.SetEndX(s.GetEndX())
    line.SetEndY(s.GetEndY())
    line.SetStartX(s.GetX())
    line.SetStartY(s.GetY())
    board.Add(line)

pcbnew.Refresh()

Select the wanted track segments (straight lines, not arcs). Open Tools → Scripting Console. Open the context menu there, over the ‘>>>’ prompt line. Use Paste and Run. If everything goes fine, you will have graphic lines in your board. But you probably want to modify this a bit: the number 50000 is 0.05 mm which is added to the line width, to take care of the mask clearance. You can change it. If you have arc tracks, they need more scripting. Also, this doesn’t work for other than the front layer tracks because of hard coded layer name – you can change it for back layer.

Thanks eelik.

The only decent way I’ve found to do this is a bit round-about. First, export the tracks you as Gerbers. Load the Gerber file into the Gerber Viewer, and export it as a KiCad PCB. At that point you can choose which layer you want to export to.

Then open the PCB in PCBNew, delete everything you don’t want, copy the bits you do want and paste into your PCB.

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