The use of a script for setting up a GUI is something I have not gotten into. I spent a fair bit of time on Google yesterday and every link pertaining to how to do that for older versions is broken or redirects to Autodesk. One comment, maybe by Jorge, suggests it is done with a "C-type language."
My experience with any high level language is virtually nil. I do not do C. ... I also do some simple command line entries in Eagle, but nothing I have tried to save as a ulp or scr.
So you already know that for any GUI action on your project can also be entered as a text command in the CLI window. That's a start.
What I was looking for was a description of the Eagle script -- maybe a tutorial.
Would you be willing to share what you wrote for the grid that could be used as a model for modification?
Sure, I'll try. I don't know how far you'll get without C or other HLL experience.
-
EAGLE extensions are very "clever." Which is not at all the same as "elegant", but it does fit my personality.Everything is tied to the "cli commands."
-
The "menu" command lets you tie any text command to some menu buttons."initialization" scripts load at startup, and can distinguish between SCH/BRC/LBR...
So, for example, in the schematic editor I added a menu that has my favorite parts, so I don't have to keep going to the ADD panel:
menu 'R {1/4 W TH : add R-US_0207/10 | \
SMT1206: add R-US_R1206 \
}' \
'C: add C-US*' \
'CPOL: add CPOL-US*' \
'WIRE: add WIRE-via8@mylib4' \
'GND: add gnd@supply1' \
'VCC: add vcc@supply1' \
;
It ends up looking like:
The syntax is a bit ugly, but relatively straightforward until you make your menus too deeply nested.
-
Since the menu buttons can have any EAGLE cli command, they can also invoke "Scripts" or "ULPs".
A "script" (.scr file) is just a file with a bunch of EAGLE cli commands in it. It can "do things" to your project, but it does so "blindly", so it can't (for example) say "set the grid to half of its previous size" because while it has access to the "grid" command, it doesn't have any access to the old grid size.
-
"User Language Programs" are where you get to "C-like syntax." Essentially "C with strings, objects, and libraries", you get your standard programing constructs, plus the ability to pop up dialog boxes (ugly, again), plus read-only access to much of the data that makes up your board, schematics, and a fair amount of EAGLE internal data structures.
To actually DO anything, a ULP generates a string or file that is a Script.For better or worse, there are MANY existing ULPs, and they're widely shared, so you can build up a useful menu that uses ULPs without actually having to write C-like code.
-
My Board "menu" looks like:
menu 'Layers {\
Top : display NONE top torigins tKeepout tRestrict borigins pads vias dimension unrouted; | \
Bottom : display NONE bottom borigins bKeepout bRestrict torigins pads vias dimension unrouted; | \
All : display top bottom pads vias dimension unrouted tplace \
torigins tnames tvalues bnames bvalues trestrict bplace borigins brestrict Document ?? Edit_history; | \
NoNames : display -tnames -tvalues -bnames -bvalues; | \
noDocu : display -tdocu -bdocu; | \
AddDocu: display tdocu bdocu Document ?? Edit_History; | \
SilkScreen: display NONE tplace -tvalues -tdocu dimension top tStop; \
}' \
'TogScreen : run toglays 21 22 25 26 27 28 51 52;' \
'DrawOn {\
Top : change layer top; | \
Bottom : change layer bottom; | \
tPlace : change layer tPlace; | \
Dim : change layer Dimension; | \
History: change layer History; \
}' \
'Grid {\
Toggle : run gridhalf 1 t ; info | \
Smaller : run gridhalf 0.5; move | \
Bigger : run gridhalf 2; move | \
OnOff : grid; move \
}' \
'Circle : run circle;' \
'Count : run count;' \
'DrlAid : run drill-aid;' \
'RipPoly : ripup @;' \
;
Note "Count" and "DrlAid" which simply run the EAGLE-provided ULPs.
The "Grid" menu (sub-menus Taggle, Smaller, Bigger) runs a ULP (gridhalf.ulp) I wrote with arguments that include a multiplier, and whether the units should change. The ULP reads the current grid info from the board data structures, multiplies it by the factor provided, constructs a new "grid NNmm" command (or whatever) and returns that string, which is executed as a script and changes the grid. There are some other complications associated with changing the units at the same time, but I don't remember exactly what they were :-(
gridhalf.ulp looks like:
#usage "<qt><b>gridmult.ulp <mult> m|i|t"
"<p>Multiply the current grid setting by a factor."
"<p>"
"<author>Author: Bill Westfield xxxxxx@xxxxxx</author></qt>"
real griddistance;
real multiplier = 1.0;
string cmd = "";
string units;
string newgrid;
UL_GRID oldgrid;
char arg2;
string gu2str (int unittype)
{
switch (unittype) {
case GRID_UNIT_MIC:
return " mic";
case GRID_UNIT_MM:
return " mm";
case GRID_UNIT_MIL:
return " mil";
case GRID_UNIT_INCH:
return " inch";
}
}
if (board) board(B) {
oldgrid = B.grid;
} else if (library) library(L) {
oldgrid = L.grid;
}
if (argc > 0) {
if (argc > 2) {
if (oldgrid.unit == GRID_UNIT_INCH) {
newgrid = "grid mm;";
} else {
newgrid = "grid inch;";
}
} else newgrid = "";
multiplier = strtod(argv[1]);
griddistance = oldgrid.distance * multiplier;
if (oldgrid.unit == oldgrid.unitdist) {
/*
* original units still being used. No conversion necessary!
*/
sprintf(cmd, "grid %f;%s\n", griddistance, newgrid);
exit(cmd);
} else {
/*
* We have to play with units. We could convert, but let's
* switch the commands around instead (gives us compatibility
* with the menus, hopefully!)
*/
sprintf(cmd, "grid %s; grid %f; grid %s;%s\n", gu2str(oldgrid.unitdist),
griddistance, gu2str(oldgrid.unit), newgrid);
exit(cmd);
}
}
(look at that lovely comment about needing to "play with units" but not WHY. Sigh.)