Electronic – Is it possible to run EagleCad’s DRC from a terminal, and pipe the error list to a file

eagle

I currently use EagleCAD to capture my schematics and route my circuit boards. Eagle isn't very pleasant to work with, so I've started working with schematics and boards outside of Eagle's GUI by directly editing the SCH and BRD files; calling Eagle commands from the system command line when needed. (Just to be clear, I mean calling Eagle commands from an external script or a CMD or terminal window, not from the little textbox "command window" inside the Eagle GUI.)

I'd like to be able to handle DRC and ERC from outside of the Eagle GUI, but I'm unsure how. I can, for instance, call the Eagle DRC from the command line with "eaglecon -C DRC;QUIT; [board name]", but this just opens the Eagle GUI, lists any DRC errors in a dialog window inside the GUI, and then closes the GUI. I would like to get the list of DRC errors as text in the command window, so they can be piped to a file.

Any ideas if this is feasible? Thanks

Best Answer

Okay, I figured it out (and the anonymous comment pointing out the Eagle Exchange forum helped).

You can't pipe the DRC output by running it directly from the command line, but starting with Eagle 7.x you can access a UL_ERROR object in User Language Programs (ULPs). Cadsoft's ULP manual (v7.2) gives the details. Here is a sample program to print all DRC errors for a given board:

string errstring;
string errheader;
string errlist[];
int errcnt = 0;
real xadj, yadj, finest_unit;
finest_unit = 0.000000123031496; //assuming grid is in inches

errheader = "code\tstate\tdescription\tlayer\tsignature\tx\ty";

if (board) {
    board(B) {
        if (B.checked) {
            B.errors(ER) {
                if (ER.state == ERROR_STATE_ACTIVE) {
                    xadj = ER.x * finest_unit;
                    yadj = ER.y * finest_unit;
                    sprintf(errstring, "%d\t%d\t%s\t%d\t%s\t%f\t%f", ER.code, ER.state, ER.description, ER.layer, ER.signature, xadj, yadj);
                    errlist[errcnt++] = errstring;
                }
            }
        }

        string filepath = [full path to desired output text file];
        output(filepath) {
            printf("Grid size=%f\n", B.grid.distance);
            printf("Grid unit=%d\n\n", B.grid.unit); //compare to grid constants in manual
            printf("%s\n", errheader);
            for (int i = 0; errlist[i]; ++i){
                printf("%s\n", errlist[i]);
            }
        }
    }
}
exit (0);

Save this in (for example) Eagle's ULP directory as foobar.ulp. This can then be called from the command line with something like

eaglecon -C "DRC; RUN ../ULP/foobar.ulp;QUIT;" [full path to board]

The quotes in that command are necessary.