When I import DXF files the line width defaults to 2.54mm. On the OS X version I can only change the widths one line at a time, except for one time I selected the lines and an option appeared to set them all at once to the default width set in Preferences. I cannot find that option again.
Does anyone know how to set all the selected line widths in one go?
import pcbnew
board = pcbnew.GetBoard()
for drw in board.GetDrawings():
if drw.IsSelected():
drw.SetWidth(int(0.1 * 1e6))
Above snippet sets line width for all selected drawing elements (lines etc.) to 0.1 mm. Note that 1e6 multiplier is required because internal units of kicad is nanometers.
Hi, dumb question. I’ve tried this but can’t seem to get it to work. I select my lines I want to change in OpenGL view, drop this code into the Shell tab of the Scripting console, hit enter and nothing changes. Am I missing a step? I never use the scripting console, just CLI from an xterm. This would be a great way of doing things if I could get it to work:)
Well, it seems that if I use the shell and run this using execfile(“thatfile.py”) it works. Not sure why it wouldn’t work the other way… very confusing. Anyway, nice to know that I can do this within pcbnew, this make life much easier!!!
In most cases, you have to refresh the canvas to see the changes. Currently only way I know for doing this which doesn’t involve editing the board is to switch canvases back and forth.
Funny, I tried that with just dropping the code into the shell, but it didn’t seem to work. Tried F3/redraw with no luck as well. Running the scrip via execfile seemed the be the only thing that worked. Now I’m off to find out how to append a board file:)
Nice thing about running it as a script is I can used raw_input like so:
import pcbnew
board = pcbnew.GetBoard()
raw_input(“Please select lines to change (Enter to continue)”)
new_width = float(raw_input("Please enter the new Width in mm: "))
new_width =new_width * 1e6
for drw in board.GetDrawings():
if drw.IsSelected():
drw.SetWidth(int(new_width))
Oh, I got another dumb question. Is there a way to select all elements of a particular layer? For example, going back the the original question regarding the DXF coming in at 2.54mm, could you automatically select everything on layer 44 and and then exec this code?
@Mike_Lemon you enter those Python commands into the “scripting console”. You can copy and paste it in there as well. You can open the console from the “Tools” menu. I’m not sure if kicad stable version does have it. I think you have to install the nightly version.
Ah ok sorry for the delay I’m currently using a quite recent nightly version and after selecting the silk screen lines in openGL
opening the scripting console pasting this in:
import pcbnew
board = pcbnew.GetBoard()
raw_input(“Please select lines to change (Enter to continue)”)
new_width = float(raw_input("Please enter the new Width in mm: "))
new_width =new_width * 1e6
for drw in board.GetDrawings():
if drw.IsSelected():
drw.SetWidth(int(new_width))
and hitting enter it doesn’t do anything.
I know it might seem like I’m as dumb as a rock but I don’t realy understand this kicad phyton thingy.
@Mike_Lemon I also noticed pasting the script doesn’t work sometimes. Try pasting code with the Edit menu -> Paste Plust command. This is in the menu of the scripting console.
Also, to see the results, you should somehow trigger a re-draw. Sometimes moving the cursor works. Sometimes I have to switch between old canvas and backto new opengl canvas. You can use F9 and F11 shortcuts.
Easier way to run a script is to add it as an external plugin. You should check this thread for info on that.