Laying out Leds in a Circle

Hi,

First time working with KiCad after previously making a few boards with eagle.

I saw there were a few other threads on how to layout footprints in a circle, however I really have no understanding of how scripting/python work.

I’m trying to follow this tutorial. But I’m a bit lost. My understanding is that I’m supposed to save the script in a specific place and then just type " import nameofscript.py" into the scripting console. I also don’t understand where I’m supposed to save the file. Can I create my own KiCad library folder and connect that directory to kicad?

Thanks

I avoid implicit paths, and place my Python scripts anywhere, and then I include a comment in the .py file, of how to launch it, in the scripting console, like this

# eg Usage - in KiCad PcbNew Python Console paste after >>>
# >>> execfile("C:\KiCad_Python\Check_Footprint_Attr\PcbNew_Select_Track_Pad.py")

Then, I just copy/paste that execfile()

Thanks for the response!

I saved the python file from the tutorial on my desktop.(I’m on a mac also)

And tried running :

execfile("~/Users/timrooney/Desktop/circle.py")

And got the errors:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
IOError: [Errno 2] No such file or directory: '~/Users/tim/Desktop/circle.py'

There seems to be two issues. One i’m guessing is with my file path? And the other I’m unsure.

Anything thoughts? And does anything need to be me changed or added to the actual python file for this to execute correctly.

Looks like one issue, ie it cannot find that path.
The example I gave was for windows, so I’m not sure how mac manages the finer points of paths.
Does the mac have an equivalent to a Drive:\directory\tree\file.py ?

1 Like

You need to remove the ‘~’. The tilde represents your home directory so by including it you are passing a path of ‘Users/timroony/…’ within your home directory. i.e ‘/Users/timrooney/Users/timrooney/Desktop/circle.py’ which obviously doesn’t exist.

Is your username ‘tim’ or ‘timrooney’ - you have used both in your question.

Try:

execfile("/Users/timrooney/Desktop/circle.py")

1 Like

Thanks John.That worked.

However, when I then enter:

circle.place_circle(["c1", "c2"], 0, (500, 500), 1000)

i get:

Traceback (most recent call last): File "<input>", line 1, in <module> NameError: name 'circle' is not defined

I haven’t tried running this but I would try typing;

    import sys
    print(sys.path)

This will show you where the kicad python is looking for modules. In order for you to run this, you probably need to import circle first but you need to place the script somewhere on the search path. The sys.path should give you a good idea of where to put it - probably something like /Applications/Kicad/kicad.app/Contents/SharedSupport/scripting/plugins
Move your script there and then try

import circle
circle.place_circle(["c1", "c2"], 0, (500, 500), 1000)

Also check that you have imported your netlist. Are C1 & C2 light emitting capacitors :wink: ?

So this is what I got:

['/private/var/folders/m3/sbyvfxtj29jdr_8k9x5zdh_00000gn/T/AppTranslocation/53C8E3DE-33CD-487D-873F-56BFA5CE5189/d/kicad.app/Contents/Frameworks/python/site-packages/wx-3.0-osx_cocoa', '/private/var/folders/m3/sbyvfxtj29jdr_8k9x5zdh_00000gn/T/AppTranslocation/53C8E3DE-33CD-487D-873F-56BFA5CE5189/d/kicad.app/Contents/Frameworks/python/site-packages/wx-3.0-osx_cocoa', '/private/var/folders/m3/sbyvfxtj29jdr_8k9x5zdh_00000gn/T/AppTranslocation/53C8E3DE-33CD-487D-873F-56BFA5CE5189/d/kicad.app/Contents/MacOS', '/private/var/folders/m3/sbyvfxtj29jdr_8k9x5zdh_00000gn/T/AppTranslocation/53C8E3DE-33CD-487D-873F-56BFA5CE5189/d/kicad.app/Contents/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/private/var/folders/m3/sbyvfxtj29jdr_8k9x5zdh_00000gn/T/AppTranslocation/53C8E3DE-33CD-487D-873F-56BFA5CE5189/d/kicad.app/Contents/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/private/var/folders/m3/sbyvfxtj29jdr_8k9x5zdh_00000gn/T/AppTranslocation/53C8E3DE-33CD-487D-873F-56BFA5CE5189/d/kicad.app/Contents/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/private/var/folders/m3/sbyvfxtj29jdr_8k9x5zdh_00000gn/T/AppTranslocation/53C8E3DE-33CD-487D-873F-56BFA5CE5189/d/kicad.app/Contents/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/private/var/folders/m3/sbyvfxtj29jdr_8k9x5zdh_00000gn/T/AppTranslocation/53C8E3DE-33CD-487D-873F-56BFA5CE5189/d/kicad.app/Contents/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/private/var/folders/m3/sbyvfxtj29jdr_8k9x5zdh_00000gn/T/AppTranslocation/53C8E3DE-33CD-487D-873F-56BFA5CE5189/d/kicad.app/Contents/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/private/var/folders/m3/sbyvfxtj29jdr_8k9x5zdh_00000gn/T/AppTranslocation/53C8E3DE-33CD-487D-873F-56BFA5CE5189/d/kicad.app/Contents/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages', '/private/var/folders/m3/sbyvfxtj29jdr_8k9x5zdh_00000gn/T/AppTranslocation/53C8E3DE-33CD-487D-873F-56BFA5CE5189/d/kicad.app/Contents/SharedSupport/scripting', '/private/var/folders/m3/sbyvfxtj29jdr_8k9x5zdh_00000gn/T/AppTranslocation/53C8E3DE-33CD-487D-873F-56BFA5CE5189/d/kicad.app/Contents/Frameworks/python/site-packages', '/vagrant/build/python-dest/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/vagrant/build/python-dest/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/vagrant/build/python-dest/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/vagrant/build/python-dest/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/vagrant/build/python-dest/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/vagrant/build/python-dest/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/vagrant/build/python-dest/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/vagrant/build/python-dest/Library/Frameworks/Python.framework/Versions/2.7/lib/lib-dynload', '.', '/private/var/folders/m3/sbyvfxtj29jdr_8k9x5zdh_00000gn/T/AppTranslocation/53C8E3DE-33CD-487D-873F-56BFA5CE5189/d/kicad.app/Contents/SharedSupport/scripting', '/private/var/folders/m3/sbyvfxtj29jdr_8k9x5zdh_00000gn/T/AppTranslocation/53C8E3DE-33CD-487D-873F-56BFA5CE5189/d/kicad.app/Contents/SharedSupport/scripting/plugins']

I originally tried this since it was included in the the tutorial, but the result doesn’t make much sense to me which lead me to my original confusion. Any idea why a sensible file directory isn’t appearing?

That sbyvfxtj29jdr_8k9x5zdh_00000gn business is MacOS security feature where it hides real paths from the application. In fact that maps to /Applications/Kicad/kicad.app in most cases so John_Pateman’s advice is solid.

2 Likes

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