Real Scripting. The most important feature a tool can have.

One of the dreams of Free and Open Source Software (FOSS) is that if a program doesn’t do what you want, you can add it. This is frequently said, but I don’t think it’s as true as we’d like it to be or at least not as true as it could be. Kicad is open source and used by many. It’s also missing a lot of features, but what would it take for someone to contribute?

First, it’s written in C++ which is intimidating to many. I’d guess that for many (most?) folks who want to design a PCB, C++ means Kicad is effectively closed source.

Second, even if one is comfortable with C++, many (most?) compiled projects are not so easy to replicate. Just building and running the unmodified code is an obstacle.

So most potential contributors don’t even make it out of the gate. Scripting capabilities lower the bar. Few will compile code, many might consider trying a simple hello world script.

There are lots of examples of tools with scripting out there. Adobe products, for example, have scripting. Photoshop has a macro feature that enables user to automate many tasks. Lightroom goes further. 1. Even artsy people who are completely terrified by the idea of programming can use these.

A better example is the Firefox and later Chrome browsers. To write an addon/extension doesn’t require one to know C++ or even compile anything. Javascript is all that’s needed. In the case of Chrome, the debugger is always right there. 2. These browsers are successful largely (entirely?) because of the wealth of extensions available.

Yet another example is Blender. Everything is exposed to the scripting language. Everything. Menus, bindings, direct node/edge/face manipulation. There’s nothing you do from C++ that isn’t available in the scripting language.

Kicad’s pcbnew has had python support for some time now; I wrote a message on kicad-users about it almost four years ago. Things have progressed a little, but not much. You no longer have to recompile pcbnew to use it, which is a big step.

The purpose of this blog is to help things along. I hope to better document the existing scripting features to help new potential user make real changes to pcbnew 3

At this point in the post, if you just want to get into scripting, continue to my next posts. The rest of this one is just commentary on why I think this is an important topic.

Who am I. Who is this guy?

Up til two years ago 4, I worked for a well know semiconductor manufacturer. You’ve heard of the company and it’s almost guaranteed that you’ve owned one or more of their products. I worked there for a bit over 20 years in the CAD/EDA 5 department. For 14 of those years, I worked on and supported the VLSI 6 layout editing tools used to design the most well know of their products.

The earliest of the editors didn’t have scripting. They weren’t even written in C++ which was a young/new language at the time. 7. When I took from being a tool developer to a year and a half of active floor support, I made an important niche for myself by writing simple editing macros. In meetings, when someone reported a simple/repetitive task that’s too difficult on the tools, a frequent answer was, “let’s get Miles to write a macro”. It was a nice position to be in. Some of those macros were hard to write, but most were pretty trivial… Trivial if you knew how to do it.

Eventually that generation of tools wasn’t good enough and a new one was written. 8 The new one was written in C++ with a comprehensive TCL interface 9. You can do anything through the TCL interface. The only reason to move to C++ is runtime performance. 10

The result of this scripting capability is that great new features came from some unlikely places. This company has an army of polygon pushers with no training in software. Many of these came up with some great stuff that tool developers later supported. I’ve venture to say that today, the majority of the tools’ capabilities originated this way.

There’s a small handful of kicad developers 11. There are lots of kicad users.

How many of them would try to dig through the C++ code?

How many of them would pull up the scripting window and enter a couple python commands?

That’s the power I’d like to harness.

I personally, think their “scripting” is a joke. They only enable you to invoke existing functionality. You can’t really create your own new functions. I would love to add a levels feature to Lightroom. I’ve had another idea for dealing with white balance. Alas,… can’t do it. ↩

This was all internal. Only a handful of companies do this kind of stuff and no one does nearly the amount of hand design. It made sense to develop these tools in-house and that continues to this day. ↩

Like with MAINSAIL, people hate on TCL. I think it’s a fine language that can do most things I want. A notable exception is closures/lambdas, but C++ doesn’t really have those either. C++ lambdas are very limited.↩

There was one guy switched his code to C++ for the sole reason of preventing his users from messing with it. He claimed that too often, users would modify it poorly/incorrectly and then complain to him. It was a cop out. ↩

I don’t 100% know that this is true; I’m new to the kicad world, but I’ll bet you a dollar. ↩