Adapt eCADSTAR to Your Process with Scripting

Scripting opens the door to an almost infinite number of possibilities

I will share with you an experience I encountered decades ago when I worked for a different company. I traveled to Los Angeles, to demonstrate a new interface I had written. It interpreted PCB routing data,  studied the documentation thoroughly, and tested it with the data I had. It worked fine but I went to the large corporation’s office to meet their senior engineer, he asked me to run it on his data and it failed.

I found out why, however, I could not fix it without my development environment. This was a program that read data files, not a runtime script. The third-party application (not eCADSTAR) supported a new object type that I knew nothing about. Of course, some of those objects were in his design data!

At first, this incident made me consider giving up software and doing something else. That said, after a while, I accepted it as a lesson. If I had been able to do that job with the kind of scripting I’m talking about here, I could have left that office with my head held high.

The Basics of Scripting

Scripting opens the door to an almost infinite number of possibilities. You can customize data, and how it is presented, fully to your needs. You can make common operations fast and efficient, even when they are specific to you or your team.

You do not have to create complex, advanced programs to get big benefits, but if you want to go deeper, the capability is there.

eCADSTAR scripting uses COM (Microsoft’s Component Object Model).

Even from within an external program, or applications such as Microsoft Excel, you can get access to your eCADSTAR design and library data. Using the COM interface means you access that data in the most flexible and independent way possible. You never access design objects directly, so you are never burdened with studying details of how they are implemented in eCADSTAR applications. Your scripts are also much less likely to need revision after new eCADSTAR releases, except for new capabilities, than if they accessed raw data.

Library Editor, Schematic Editor, and PCB Editor all supported scripting in multiple languages, including C#, Visual Basic, and PowerShell.

eCADSTAR customers and business partners often use scripting to extract part information into external applications they use to manage sourcing and production, but it gives you access to library and design data at deeper levels too.

Overview of eCADSTAR Scripting Interfaces

Let’s start with Library Editor. In Figure 1, I have simplified the structure and omitted many items for the sake of clarity, including, for example, the string argument passed to AddPart that contains the name of the part to be created. I have also omitted the letter “I” which stands for “Interface” and precedes the names of some classes. The full structure in all its detail is in the eCADSTAR online help.

Items in the green boxes, like Footprints, are classes, and those in the pink boxes are methods. A common dictionary definition of the word “method” is “a particular way of doing something”. These methods are the ways you can deal with each of the classes when you are scripting. A class and its associated methods comprise an interface.

This makes your scripts much less sensitive to changes in new software releases. Even if classes change, existing methods will usually remain valid and new ones will be added to support the new content.

In your scripts, you do not ever access design data directly – you use only the available methods. You are, essentially, running Library Editor, and it is giving you access to the data it is running on. That makes the process much more reliable than if your scripts or programs interpreted data files.

Figure-1-Simplified-structure-of-Library-Editor-interfaces-comprising-classes-and-methods
Figure 1: Simplified structure of Library Editor interfaces comprising classes and methods

You can do all this from within your own software development environment, if you use one, or from within applications that support scripting languages such as VBA, including Microsoft Excel.

You can mix eCADSTAR with any other application that supports the same programming language and the COM interface. Say, for instance, you use a special application to check for qualified part suppliers to your company standards and return an eight-digit part code for each qualified part. You could automate that process for your eCADSTAR library,  so that the part codes are assigned as property values.

Scripting for Schematic Editor and PCB Editor works the same way, with structured interfaces, classes, and methods. I have not shown them here, because the number of classes and methods makes the diagrams quite big. As with Library Editor, the detailed structure is described in the eCADSTAR online help.

A Simple Example of Scripting

Let’s say we wanted a list of components we have used in a PCB design, with their part names, descriptions, and footprint names. This example is a VBA macro for Microsoft Excel (Figure 2). The code size is much smaller than it would have been if it were a program reading and interpreting file contents. It requires no compilation so debugging and modifications can be done quickly. Since it is a macro within Microsoft Excel, we have a readymade and powerful way to view and work with results, too.

Figure-2-VBA-macro-code-viewed-in-Excel
Figure 2: VBA macro code viewed in Excel

The macro first gets the PCB Editor design file you want to process.

Target = Application.GetOpenFilename(“Design,*.pdes”)

Then it creates an instance of PCB Editor that it will run to access the data and opens it on the chosen PCB design.

Set App = CreateObject(“eCADSTAR.PCBEditor.Application”)

App.OpenDesign Target

To get the information and put it in the four spreadsheet columns, it steps through each component in the PCB design and accesses each value using its supplied interface.

For Each Component In Components

Cells(row, 1).Value = Component.ReferenceDesignator

Cells(row, 2).Value = Component.Part.Name

Cells(row, 3).Value = Component.Part.Description

Cells(row, 4).Value = Component.Footprint.Name

row = row + 1

Next Component

The Excel spreadsheet (Figure 3) already includes four column headers and a button called Get List. That button is configured to call this macro.

Figure-3-Spreadsheet-before-running-macro
Figure 3: Spreadsheet before running macro

When we press Get List, the macro runs and produces its results (Figure 4). Right away, we can see that descriptions are missing for three components. We might decide to fix that in the library and reload it into the PCB design. We can use these results in any way we choose, and since this is a script, we can even reference external applications in the code and use them to process this data. For example, we could add scripting to check suppliers and prices for these parts.

Figure-4-Spreadsheet-after-running-macro
Figure 4: Spreadsheet after running macro

Schematic Netlist Script

If you are an eCADSTAR user, you can download this script from the eCADSTAR online help. I made just two tiny changes in Microsoft Excel itself, not the script. I made the table color green to match the eCADSTAR Schematic Editor colors and I changed the title row so that it stayed visible when I scrolled.

This script creates a basic netlist, showing component reference designators and pins, and the nets and variants that include them. shows the results of running this script on a schematic with design variation and block hierarchy.

Figure-5-Results-after-running-schematic-netlist-script
Figure 5: Results after running schematic netlist script

Here is part of the script (Figure 6). The whole script is only around double this size. This part of the script detects if it is dealing with a variant design and, if so, inserts the name of the variant in the first column of each spreadsheet row.

Figure-6-Excerpt-from-schematic-netlist-script
Figure 6: Excerpt from schematic netlist script

Building on the downloadable scripts in the eCADSTAR help is an excellent way to get started.

The Joy of Sharing

The COM scripting interface gives controlled access to eCADSTAR apps and the data they work with. Working this way is safer than directly accessing data files and gives you control over application functions as well as data.

This also means you can share your scripts with other engineers. eCADSTAR provides a platform for doing that at eCADSTAR 3rd Party Apps. All the scripts available here, created by eCADSTAR users, have been reviewed by the eCADSTAR team before being published.

Some of these third-party apps use the COM scripting interface, and they use it in more sophisticated ways than I have illustrated in this blog. For example, Set Component Position saves and restores component locations in PCB Editor. To do that, it uses the COM interface to change design data as well as to read it.

Top Benefits of Scripting

It’s easy to see, even from the simple example I showed here, how much you can achieve with so little code in so little time. Scripting brings many more advantages. You access your design data only via eCADSTAR applications and COM interfaces you use in your scripts – never directly. That makes your scripts much more maintainable than traditional programs and data interpretation is much more reliable.

Scripting works with you in re-usable ways, in whole or in part, just as eCADSTAR applications work with you to maximize re-use in your designs.

Jane Berrie
Jane BerrieSignal Integrity Expert, Zuken Tech Center, Bristol
Jane Berrie has been involved in EDA for PCB signal integrity since the 1980s. Her articles have appeared in many publications worldwide - too many times to mention. Jane is also a past session chair for 3D IC design at the annual Design Automation Conference. Jane’s also an innovator with a unique perspective, who constantly works on new solutions in the fast-evolving world of electronic design. In her spare time, Jane has organized themed charity events - including two in aid of lifeboats and red squirrel survival. Jane is also a regular disco-goer.

Discuss Your PCB Design Opportunities With Our Experts

We can help you craft the best solution for your company’s specific requirements.
Contact Us