As I wrote the biggest script for Altium Designer

15680 lines, 800 053 characters - exactly this size today is my script created inside Altium Designer - a system for developing printed circuit boards.

image

Start


It was 2014, I worked as a design engineer, developed printed circuit boards. Military acceptance, design of complete design documentation (CD), normative control ESKD - all this makes the Australian-Chinese-American software, which is the Altium system, tremble. Because they are alien to the Soviet guests, the old instructions and standards for the design of drawings. One employee of our department sometimes spent the whole work shift in order for the drawing of the board to meet all the norms and rules for the design of the design documentation.
Now it is done in 10 minutes.

I decided that it is possible to simplify the life of myself and ten more people at work. I started to understand, I found that there is an open API, I began to look at examples and voila, my first script for Altium already draws a line on the board, there is no limit to joy.

Little by little I was expanding my programming knowledge, because before that I hadn’t come across much of it, I remember a pendulum in the university I wrote for a semester and that's it.

First interface


It got to the point where the interface had to be done, at the very beginning it was like this:

image

This version already knew how to draw dimensions, callouts with arrows.

It should be understood that there was no special explanation in the documentation, no one had any experience in using functions from the API either, only some githaba scripts and standard altium ones. Description on the wiki to this day from the category:

SetState_Enabled method
(IPCB_Primitive interface)
Syntax
Procedure SetState_Enabled (Value : Boolean);
Description
Example
See also
IPCB_Primitive interface

And the whole description, although by trial and error it was possible to determine how it works.

Each new time, the introduction of new functions was enjoyable, because when you see how people use your work and everything turns out - that’s not why programs are being created. At this stage, the time for drawing up the drawings has already been reduced almost by half.

Development


The next version already looked like this:

image

She already knew how to insert sheets into the board, to stroke polygons for a drawing, to insert a grid and other elements for a drawing.

The main problem was that the Altium development environment is a system for developing printed circuit boards. It does not have enough tools to design a CD, and even more so according to Russian standards. Basically, scripting expanded the standard environment toolkit so that you could also develop a CD and print it out.

For example, I inserted the insertion of sheets of different formats directly into the code, did not begin to make separate files. I applied excel tables for this, inserted a format file into my pcb with my hands, selected all the properties of all the lines, their coordinates, widths, coordinates of texts, etc. and put it all in the usual array. Then, the script in turn created each of the formatting lines in the board file itself. And so for each sheet of all formats.

Our days


Now the program already looks like this:

image

image

I have never been a designer, sometimes I had to sculpt the buttons, I looked at the most well-known CAD systems, how the menus, settings, drop-down buttons and so on were made there.

Here is an example of the script itself.
image

image

Total on board:

  • More than 50 settings, saving them inside the board file
  • Updating drawings when making changes to the board
  • Automatic insertion of species in the center of sheets
  • PDF formation in one button
  • Editing of sizes with recalculation of deviations on the fly
  • Radial grid, 4-sided grid, risks, custom step
  • Saving sketches in txt format for further use

and much more.

A lot of nerves, strength, patience, sleepless nights - spent. We make drawings at work - priceless.

The script is written by me alone for the fourth year, and without the use of the gita, dark themes and other things). Only pascal, only hardcore. Thank you for listening to the end, I will be glad to communicate!

An example of a decorated drawing inside the PCB

Version of the program to try

Also popular now: