{"id":6966,"date":"2017-11-03T16:35:08","date_gmt":"2017-11-03T16:35:08","guid":{"rendered":"http:\/\/blog.bachi.net\/?p=6966"},"modified":"2017-11-05T13:48:55","modified_gmt":"2017-11-05T13:48:55","slug":"kicad-python-console","status":"publish","type":"post","link":"https:\/\/blog.bachi.net\/?p=6966","title":{"rendered":"KiCAD Python Console"},"content":{"rendered":"<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ncd \/c\/Users\/bachman0\/Documents\/ZHAW_Module\/PA\/kicad\/python\/svg2mod\r\npython svg2mod.py -i ..\/..\/images\/PA17_bmat_6_V1.svg -o test1 --format pretty\r\nParsing SVG...\r\nNo handler for element {http:\/\/www.w3.org\/2000\/svg}defs\r\nNo handler for element {http:\/\/sodipodi.sourceforge.net\/DTD\/sodipodi-0.dtd}namedview\r\nNo handler for element {http:\/\/www.w3.org\/2000\/svg}metadata\r\ntransform: translate &#x5B;0.0, -295.7]\r\ntransform: translate &#x5B;-2.0552455, 280.43471]\r\nWriting module file: test1.kicad_mod\r\n<\/pre>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n\r\nsys.path.append('');\r\nos.chdir('');\r\n\r\nsys.argv = &#x5B;'arg1', 'arg2']\r\nexecfile('');\r\n\r\nsubprocess.call(&#x5B;'.\/abc.py', arg1, arg2])\r\n\r\n# \r\nexecfile('C:\\Users\\bachman0\\Documents\\ZHAW_Module\\PA\\kicad\\python\\test1.py')\r\n# Traceback (most recent call last):\r\n#   File &quot;&lt;input&gt;&quot;, line 1, in &lt;module&gt;\r\n# IOError: &#x5B;Errno 2] No such file or directory: 'C:\\\\Users\\x08achman0\\\\Documents\\\\ZHAW_Module\\\\PA\\\\kicad\\\\python\\test1.py'\r\n\r\nexecfile('C:Users\/bachman0\/Documents\/ZHAW_Module\/PA\/kicad\/python\/test1.py')\r\n# Traceback (most recent call last):\r\n#   File &quot;&lt;input&gt;&quot;, line 1, in &lt;module&gt;\r\n# IOError: &#x5B;Errno 2] No such file or directory: 'C:Users\/bachman0\/Documents\/ZHAW_Module\/PA\/kicad\/python\/test1.py'\r\n\r\nprint sys.path\r\n# &#x5B;'C:\\\\Program Files\\\\KiCad\\\\lib\\\\python27.zip', 'C:\\\\Program Files\\\\KiCad\\\\lib\\\\python2.7', 'C:\\\\Program Files\\\\KiCad\\\\lib\\\\python2.7\\\\plat-win32', 'C:\\\\Program\r\n# Files\\\\KiCad\\\\lib\\\\python2.7\\\\lib-tk', 'C:\\\\Program Files\\\\KiCad\\\\lib\\\\python2.7\\\\lib-old', 'C:\\\\Program Files\\\\KiCad\\\\lib\\\\python2.7\\\\lib-dynload', 'C:\\\\building\r\n# \\\\msys64\\\\mingw64', 'C:\\\\Program Files\\\\KiCad\\\\lib\\\\python2.7\\\\site-packages', 'C:\\\\Program Files\\\\KiCad\\\\lib\\\\python2.7\\\\site-packages\\\\wx-3.0-msw', '.', \r\n# 'C:\/Program Files\/KiCad\/bin\/..\/share\/kicad\/scripting\/plugins']\r\n\r\nexecfile('C:\/Users\/bachman0\/Documents\/ZHAW_Module\/PA\/kicad\/python\/test1.py')\r\n# 0 F.Cu\r\n# &#x5B;...]\r\n\r\n# ex.\r\n\r\nimport sys\r\nsys.path.append(&quot;\/home\/user\/path\/to\/kicad-python\/&quot;)\r\nexecfile(&quot;\/home\/user\/path\/to\/kicad-python\/examples\/pcbannotate.py&quot;)\r\n\r\nos.chdir('C:\/Users\/bachman0\/Documents\/ZHAW_Module\/PA\/kicad\/python\/svg2mod\/')\r\nexecfile('svg2mod.py')\r\n\r\nsubprocess.call(&#x5B;'svg2mod.py', '-h'])\r\n# Traceback (most recent call last):\r\n#   File &quot;&lt;input&gt;&quot;, line 1, in &lt;module&gt;\r\n#   File &quot;C:\\Program Files\\KiCad\\lib\\python2.7\/subprocess.py&quot;, line 169, in call\r\n#     return Popen(*popenargs, **kwargs).wait()\r\n#   File &quot;C:\\Program Files\\KiCad\\lib\\python2.7\/subprocess.py&quot;, line 321, in __init__\r\n#     errread, errwrite)\r\n#   File &quot;C:\\Program Files\\KiCad\\lib\\python2.7\/subprocess.py&quot;, line 571, in _execute_child\r\n#     startupinfo)\r\n# WindowsError: &#x5B;Error 193] %1 ist keine zul\u00e4ssige Win32-Anwendung\r\n\r\nprint sys.executable\r\n# C:\/Program Files\/KiCad\/bin\/kicad.exe\r\n\r\nsubprocess.call(&#x5B;sys.executable, 'svg2mod.py', '-h'])\r\n# not a good idea\r\n\r\nsubprocess.call(&#x5B;'python', 'svg2mod.py', '-h'])\r\n# not a good idea\r\n\r\n<\/pre>\n<p><a href=\"http:\/\/docs.kicad-pcb.org\/doxygen\/md_Documentation_development_pcbnew-plugins.html\">KiCad PCB EDA Suite &#8211; Python Plugin Development for Pcbnew<\/a><\/p>\n<p><a href=\"http:\/\/kicad-python.readthedocs.io\/en\/latest\/\">Welcome to KiCad Python API\u2019s documentation!<\/a><\/p>\n<p><a href=\"https:\/\/forum.kicad.info\/t\/kicad-on-os-x-how-to-use-python-scripts-solved\/1004\">KiCAD on OS X &#8211; How to use python scripts? [solved]<\/a><\/p>\n<p><a href=\"https:\/\/kicad.mmccoo.com\/kicad-scripting-table-of-contents\/\">Kicad Scripting Table of Contents<\/a><br \/>\n<a href=\"https:\/\/kicad.mmccoo.com\/2017\/02\/01\/the-basics-of-scripting-in-pcbnew\/\">The basics of scripting in pcbnew<\/a><br \/>\n<a href=\"https:\/\/kicad.mmccoo.com\/2017\/02\/01\/modifying-pcbnew-layout-from-python\/\">modifying pcbnew layout from python<\/a><\/p>\n<h3>Scripts<\/h3>\n<p><a href=\"https:\/\/github.com\/KiCad\/kicad-library-utils\">github.com\/KiCad\/kicad-library-utils: KiCad utilities<\/a><br \/>\n<a href=\"https:\/\/hasanyavuz.ozderya.net\/?p=256\">PCB back annotation in KiCAD with Python<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>cd \/c\/Users\/bachman0\/Documents\/ZHAW_Module\/PA\/kicad\/python\/svg2mod python svg2mod.py -i ..\/..\/images\/PA17_bmat_6_V1.svg -o test1 &#8211;format pretty Parsing SVG&#8230; No handler for element {http:\/\/www.w3.org\/2000\/svg}defs No handler for element {http:\/\/sodipodi.sourceforge.net\/DTD\/sodipodi-0.dtd}namedview No handler for element {http:\/\/www.w3.org\/2000\/svg}metadata transform: translate &#x5B;0.0, -295.7] transform: translate &#x5B;-2.0552455, 280.43471] Writing module file: test1.kicad_mod sys.path.append(&#8221;); os.chdir(&#8221;); sys.argv = &#x5B;&#8217;arg1&#8242;, &#8216;arg2&#8242;] execfile(&#8221;); subprocess.call(&#x5B;&#8217;.\/abc.py&#8217;, arg1, arg2]) # execfile(&#8216;C:\\Users\\bachman0\\Documents\\ZHAW_Module\\PA\\kicad\\python\\test1.py&#8217;) # Traceback (most recent [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6966","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/6966","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6966"}],"version-history":[{"count":13,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/6966\/revisions"}],"predecessor-version":[{"id":6981,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/6966\/revisions\/6981"}],"wp:attachment":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6966"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6966"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6966"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}