How to spread footprint by calculate XY coordinates

Hi everybody
I already posted forum about creating a RGB leds controller that pcb has more than 1000 components …
Please someone can help me how I can spread all the footprints by Calculate XY coordinates. .
My question is about calculating XY positions by math (Like we r using method during footprint creation ).
Thanks

Please give all the relevant information about your needs here, or at least a link to the post where you give it. It’s impossible to say anything with this little knowledge about your needs.

Mwa,
1000 (similar? all led’s?) asks for automation, and automaton reeks of scripting.

There are a few locial ways to automate with scripting.
You can use “action plugins” right in Pcbnew.
You can search a bit for already existing scripts for componenst placement.
Or you can start from scratch, or only re-use the (Python) scripts for working with / generating PCB files.
You can read a complete PCB file into a python program with about a handfull of lines written in Python, and after that it is just a quest for filling in the right X and Y coordinates (and rotation) for your components.

The clock designed with skidl is possibly a good start with learing to use python scripts in KiCad:
https://xesscorp.github.io/skidl/docs/_site/blog/two-easy-pieces

I have to add:
I never used any kind of scripting in KiCad myself, so others may be able to give better advice on this topic. The Skidl clock is quite old.

Take a look at Place footprints: action plugin action plugin

1 Like

I have never used any scripting so if it is one time task I would put this 1000 elements by hand using user grid (only points you wont your elements to be placed).

I am also in doubt whether I would dive into scripting for a one-off project myself.
Another approach may be to make an array of your LED footprints in Pcbnew.

Inserting an array of footprints is easy, but I’m not sure about assinging the reference designators, so your Footprints match the schematic symbols.

On the other hand, working with a script may be easier then you (and I) assume. and it might be worth giving it a try. Set a time limit on how much time you’re willing to spend on it, and at the end of that time, review your methods.

I am a C/C++ programmer. After looking at Dave Vandenbout’s "Two Easy Pieces" SkiDL projects at the website you mentioned, I see that Python scripting is a very powerful technique for extending pcbnew’s toolset.

However, a few questions pop up, namely, which file does the python program read and how? which file does the python program write and how? (as in which line of code) Perhaps Dave explains this somewhere else on his website. Or MitjaN on his github webpage. I haven’t taken time to peruse either of them.

I understand Python is an interpreted language, not a compiled language. But I have not programmed with it.

So I would suggest starting a new category pertaining to “Python Programming w/ Pcbnew”, or “Offline scripting w/ Pcbnew”, or something along those lines. I am excited to think of the range of possibilities such numerical computation would add to what Pcbnew can already do. (If such a category already exists, please direct me to it!)

Just an idea,

We have a plugin category. You can start a thread there. If there is enough activity then maybe a new category could be considered but there hasn’t been a lot of programming specific posts. Programmers tend to be ‘lone wolfs’. :wink: Just some questions asked and answered on a few specifics from time to time as I recall.

@Russ The first of the “2 Easy pieces” of skidl is a stand-alone library for python.
It’s run directly in Python. Note that the last 2 lines of the first piece are:

ERC() # Look for rule violations.
generate_netlist() # Generate netlist file.

And this generates the netlist, and therefore completely “skips” Eeschema().
Then Pcbnew is started, and the second part is:

… , and then executed it in PCBNEW ’s Python shell:

Python is, (or at least used to be) an interpreted language. It seems that Python3 is nowadays “automatically” compiled before a program is executed.
There is a long standing problem with Python because 2 incompatible versions co-exist. (V2 and V3) After 10 years, there finally is some initiative to make Python2 obsolete (maintenance stops in 2020). About half a year ago (around the introduction of KiCad V5) there were some troubles because of this. KiCad uses a (wxWidgets) Python library which is/was not yet available for Python 3.

Okay, I found that. Thanks.
What about pip ?
Open source: https://github.com/xesscorp/skidl
What is pip ? I haven’t heard of it. Cannot find it in my Debian repo:
russ@solydxk1:~$ which pip

russ@solydxk1:~$ apt-cache madison pip
N: Unable to locate package pip

from reading
https://xesscorp.github.io/skidl/docs/_site/index.html#installation

I did find the python shell in kicad 5.0.2, starting with

Py 0.9.8
Python 2.7.13 (default, Sep 26 2018, 18:42:22) 
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Startup script executed: /home/george/.config/kicad/PyShell_pcbnew_startup.py

So I see that I have version 2.7.13.

Pip is a package installer for Python.

paul@dualcore:~$ apt search python-pip
Sorting… Done
Full Text Search… Done
python-pip/testing,testing,now 18.1-5 all [installed]
Python package installer

After installing it you can:

paul@dualcore:~$ man pip

Or have a look at:

https://duckduckgo.com/html?q=python+pip+manual
https://pip.pypa.io/en/stable/installing/

And I’m not a big fan of it, as it goes around apt and I have no idea of how well those libs are scrutinsed, but it’s Python and readable source, so you can read it. (Or should be able to, in theory at least, hopefully).

On my Buster Box I run KiCad V5.1.0, and according to my version info, Python scripting should be enabled, but when I:

Pcbnew / Tools / Scripting Console

… I get:
image
To me it does not matter much, because I can not scrape enough concentration together to dive deep into Python scripting even if it would work.
But if this is important to you, then be carefull, as the the troubles between Python V2 vs V3 still are not over.
I’ve heard some rumours that KiCad V6 will have a more stable Python scripting interface (for both Pcbnew and Eeschema (maybe / hopefully), but no guarantees).

Application: kicad
Version: 5.1.0+dfsg1-1, release build
Libraries:
wxWidgets 3.0.4
libcurl/7.64.0 OpenSSL/1.1.1c zlib/1.2.11 libidn2/2.0.5 libpsl/0.20.2 (+libidn2/2.0.5) libssh2/1.8.0 nghttp2/1.36.0 librtmp/2.3
Platform: Linux 4.19.0-4-amd64 x86_64, 64 bit, Little endian, wxGTK
Build Info:
wxWidgets: 3.0.4 (wchar_t,wx containers,compatible with 2.8) GTK+ 3.24
Boost: 1.67.0
OpenCASCADE Community Edition: 6.9.1
Curl: 7.64.0
Compiler: Clang 7.0.1 with C++ ABI 1002

Build settings:
USE_WX_GRAPHICS_CONTEXT=OFF
USE_WX_OVERLAY=ON
KICAD_SCRIPTING=ON
KICAD_SCRIPTING_MODULES=ON
KICAD_SCRIPTING_PYTHON3=ON
KICAD_SCRIPTING_WXPYTHON=ON
KICAD_SCRIPTING_WXPYTHON_PHOENIX=ON
KICAD_SCRIPTING_ACTION_MENU=ON
BUILD_GITHUB_PLUGIN=ON
KICAD_USE_OCE=ON
KICAD_USE_OCC=OFF
KICAD_SPICE=ON

Now, I am not a Linux issues exper, but I’d guess you have a wx incompatibility. The KiCad main app was built against wxwidgets3, but for python you are using Phoenix (wxwidgets4). If you built it, you’ll have to rebuild it with KICAD_SCRIPTING_WXPYTHON_PHOENIX=OFF. But I don’t know if this is possible on your platform

I have Python 2.7.13 on debian stretch. I am wary of “rebuilding” any useable software because I have no experience with cmake, so it could take me a day or more of work and still not produce an executable file. Instead, I downloaded another favorite math tool, octave 4.0.3, and am searching to see which toolkit (or whatever octave calls its bundles of functions) has the toeplitz() function so that I can review the numerical computational technique called Galerkin’s method of weighted residuals, a century-old numerical method for doing finite element analysis.

Have you looked at SageMath? Sadly, you have to build that one on Debian too. :frowning: I think it actually includes Octave if I remember correctly.

You probably also have python3:

paul@dualcore:~$ python --version
Python 2.7.16
paul@dualcore:~$ python3 --version
Python 3.7.3

1 Like
russ@solydxk1:~$ python --version
Python 2.7.13
russ@solydxk1:~$ python3 --version
Python 3.5.3

Yes, apparently I do. Thank you for informing me of its name.

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