What type of language would you prefer for writing KiCad scripts?


#1

Recently I started learning Python, I’ll get the hang of it but it may not very easy to learn for non-programmers.
I also recently played with Eagle ULPs, they are quite powerful, have a C like syntax, but have a BASIC like ease of use. Other tools for engineers often used BASIC like languages in the past, possibly they are becoming more C like today.

So for those non-programmers out there, I have a question:

What type of language would you prefer for writing KiCad scripts?

  • Python (current method)
  • Like BASIC
  • Like Eagle ULP
  • Other
  • I am not interested in scripts!

0 voters

I am just dipping a toe in the water here, it might be a dead end, so any constructive ideas welcome.

Edit: I meant Eagle ULPs, not Eagle command scripts


KiCommand released on github - Easy pcbnew command strings; 4.07 & nightly
#2

Your reference to Eagle Scripts are more properly called .ulps (use programming language).
I would prefer an interface like Eagles’ command language. Macros or command line scripts (.scr) would be a LOT easier for non programmers. Every menu command, parameter, etc, can be issued as a line of text, chained together sequentially and repeated to do what would be tedious tasks with the mouse. A series of keystrokes and menu selections assigned to a single key or written to a named file to be executed on command. In Eagle, command scripts can also call .ulps when necessary. Command Scripts can be used to set up eagle for a particular design task instead of doing it manually.

In short, everything that you can do with the mouse and menu selection can be done with a stored .scr file. Think of it as a shell language for KICad. KiShell anyone?

Some examples.
(http://www.autodesk.com/products/eagle/blog/what-you-didnt-know-about-eagle-script-files/)

(http://www.autodesk.com/products/eagle/blog/what-you-didnt-know-about-eagle-command-line/)

A pdf of a scripting tutorial.
(http://www.blunk-electronic.de/pdf/Scripting_en.pdf)

Can it be written in Python once the api is protected as noted by Wayne Stambaugh
(https://lists.launchpad.net/kicad-developers/msg28750.html)


#3

Well, I had never used Eagle before but after a quick Google I had a simple ULP script going. It’s a hell of a lot easier than KiCad. I’ve still not managed to get a python script to run.


#4

Look at the references I added.


#5

I never had run a KiCad script. From long time I even didn’t know about its existence! :open_mouth:
I think they need a better UI integration and easy of use so users can start notice it.
Another language suggestion: LUA ?


#6

It seems the majority supports the status quo, and there is little appetite for something different.

In a way that is good, because it means I can go ahead and implement something for myself without worrying about anything else.

A recent topic which prompted this post is How to plot component values in version 4.0.5?. Ideally I would like to open a command window, then type something like

foreach pcb.module.value (V)
V.layer = SilkS

and that would be it. To save it, I type “save setlayer”, to re-run, I type “run setlayer”.

Currently, even if the user can figure out how to run python scripts, there appears to be no way to set the layer property of module texts.


#7

Well, you would be an ideal tester.

Here is an error message I got in a recent KiCad session, can you work out what it means?

>>>test.testfunc()
Traceback (most recent call last):
File “<input>”, line 1, in <module>
File “c:/temp2/test.py”, line 7, in testfunc
print “module %s val: %s” % ( module.Ref(), module.GetValue() )
File “C:\Program Files\KiCad\lib\python2.7\site-packages/pcbnew.py”, line 5769, in
__getattr__ = lambda self, name: _swig_getattr(self, MODULE, name)
File “C:\Program Files\KiCad\lib\python2.7\site-packages/pcbnew.py”, line 74, in _swig_getattr
return _swig_getattr_nondynamic(self, class_type, name, 0)
File “C:\Program Files\KiCad\lib\python2.7\site-packages/pcbnew.py”, line 69, in _swig_getattr_nondynamic
return object.__getattr__(self, name)
AttributeError: type object ‘object’ has no attribute ‘_getattr__’


#8

Me? No, no idea… I know nothing about python.


#9

Ok, fair enough! I struggled too. Basically it is saying an attribute I used doesn’t exist, but doesn’t tell me which one.

What about this helpful comment in a “basic example” for KiCad I found:

# the find method returns an iterator to all matching nets.
# the value of an iterator is a tuple: name, netinfo

Do you understand what iterator and tuple mean here?


#10

I may know from C++ what an iterator is.
I also understand the concept of the “tuple” in that case…
but I couldn’t use it without an example code.


#11

Ah, I am assuming that the average electronic designer does not know C++, perhaps that is not true nowadays?

Back when I was learning, we had a FORTRAN introductory course. :slight_smile:


#12

True. I have very little coding experience and would very much prefer macros with just a simple record and play function for repetitive tasks. Although scripts are powerful, it doesn’t help me since I don’t master it. So what’s the reason for macros being removed from Kicad?


#13

I don’t know Python, but know a few others. It looks to me like the error is being thrown by pcbnew.py. In most languages, something like “getattr” would be a function that returns a particular attribute (sometimes referred to as properties) of an object (ex: objectname.getPrice or objectname->getPrice). The error is stating the object doesn’t have an attribute named ‘getattr_’. You would need to determine exactly what properties/attributes that particular object has available. I hope I made sense, here.


#14

Fair question, Wayne’s answer is https://lists.launchpad.net/kicad-developers/msg24267.html

Users have complained in the past the macro code doesn’t do anything
useful and I could never get it to anything useful either. I sent out
message over a week ago about getting rid of the macro code. No one
complained including you. You should have spoke up so I didn’t waste my
time removing it. I’m curious exactly what it is you are using them for
because I cannot seem to record anything useful.

Wayne

tldr; there were too many bugs in the macro code and no one has volunteered to fix them.


#15

Thanks for the info. Well, I fully understand why it’s being removed if no one wants to fix the code. Pity though, macros are really quite useful when you need to take care of different shortcomings in an application. I have a problem right now that easily could have been solved with a macro, instead I have to click and change properties for every single footprint on my current board.


#16

Yes, I’m aware of your problem which is why I started this topic.

I think macros do have a place. For this particular problem, how would you create the macro? There is no global edit feature in the GUI.


#17

Yes, I’m aware of your problem which is why I started this topic.

Hey, thanks for reading my post :slight_smile:
A global edit feature would have been nice but something similar to “Actions” used in Photoshop would be fantastic. I understand the scope quickly becomes big and complicated to code, but if I just could wish for something;

Invoke a small popup window where you first define a new macro (“action”), then push the record button to record your actions; mark an object (footprint, track or via), call a function from the meny or change its properties (except for position).Then a Stop and Save Macro to file. Since there aren’t any list of objects available, maybe a multi-marking function could create and hold a temporary list: Press a Hotkey, click an object and see a list with added objects. Load your macro and press Play (and obviously a Stop button). If a particular function can’t be executed on a certain object, it’s simply bypassed. Does that makes sense?


#18

When I was starting at university, there were rumors that some guy named Wirth came up with a language called “C”.
Have we grown to be THAT old? :slight_smile:


#19

Wirth? You must be thinking of Pascal? It was Dennis Ritchie who created C.


#20

Yes, of course. So Dementia is lurking around the corner… :slight_smile: