On windows kicad installer contains it’s own python executable and libs. You have to use that if you want your scripts to be able to access pcbnew module, which the script provided by adamws does. So instead of just typing python in cmd you have to put full path to python.exe that is in kicad’s install directory.
For example:
Note the quotes around the path, they are necessary if you have spaces in the folders.
The command above also assumes that the working directory of your cmd window is where the zonefiller.py file is. If not then provide full path to the script too.
That command must have some output, it will not fail silently, if you still have an error post the output here.
Ok I did as you sad, executet cmd in the folder, where zonefiller.py is located and got this error:
C:\testpy>"C:\Program Files\KiCad\bin\python.exe" zonefiller.py
Traceback (most recent call last):
File "zonefiller.py", line 5, in <module>
board = pcbnew.LoadBoard(board_path)
File "C:\Program Files\KiCad\lib\python2.7\site-packages/pcbnew.py", line 6876, in LoadBoard
return _pcbnew.LoadBoard(*args)
IOError: Unable to open filename "C: estpy\manual_1.kicad_pcb" for reading
I tried different folders but a part of the path in the last line is always missing.
The path should be: “C:\testpy\manual_1.kicad_pcb” and is correctly writen in the “zonefiller.py” file.
Could this be the Problem?
Yes, that is the problem. In python normal strings use backslash \ for escaping, it is interpreting \t as a tab char. To fix this either use double backslash C:\\testpy\\manual_1.kicad_pcb or raw string by prepending r before the string like this r"C:\testpy\manual_1.kicad_pcb" to disable escaping.
Do you have multiple kicad versions installed? That sounds like either the file got corrupted by earlier manipulations or you are using python from older kicad to try to open file created by newer kicad.
I had KiCad 5 installed and used the path: “C:\Program Files\KiCad\bin\python.exe” zonefiller.py.
The right path is: “C:\Program Files\KiCad\7.0\bin\python.exe” zonefiller.py
I used the Path without the \7.0 an therefore the python version for KiCad 5.
Do you think its possible to call that function with cmd and hand over the boardpath?
If it´s possible with a python scirpt, I would prefer not accessing the sourcecode.
I don’t think you can call those from python but at least the clean up doesn’t do much beyond removing 0 length segments and combining collinear and coincidental segments. It can be reimplemented in python.
Import graphics doesn’t have an easy solution though.
Ok. I want to use the Cleanup, because some .dxf Files that i´m importing have two outlines ontop off each other(collinear).
At the moment i´m deleting them with
But i want to automate it, the same way we did with the ZONE_FILLER further up in this post.
To have a skript that can be run with cmd, so i don´t even have to open any Programm und just run this skript.
I don’t think there is API for it. If you have to automate it you will have to use mouse/keyboard emulation and automate launching the program and clicking menus/buttons with macro recording software. It’s not clean but it works.