/****************************************************************************** * SNAP50.ULP - please send any comments to hv@itec-audio.com * * This EAGLE User Language Program produces a script * file that can be used to snap the elements of the * current board to a given grid. * * V1.1 01.06.99 Helmut Vaupotitsch - hv@itec-audio.com * * SkipThisElements: Skip elements which start with special strings * * SkipElements = No|Yes * SkipElements = No: Snap all elements * SkipElements = Yes: Snap elements defined in "SkipThisElements". * * Output-script in "Target" (snap.scr) * Errorlevel -1: Drawing is not a board * *****************************************************************************/ real GridDist = 50.0; // in Mil, can be changed to other values string SkipThisElements[] = // Skip elements which start with the following strings {"ST","S1","S2","S3","S4","S5","S6","S7","S8","S9","S10"}; enum {No, Yes}; int SkipElements = Yes; string Target = "snap.scr"; enum { OK=0, NotABoard=-1 }; int ExitCode; real snap(int n) // returns next grid point { return round(u2mil(n) / GridDist) * GridDist; } ExitCode = NotABoard; if (board) board(B) { ExitCode = OK; output(Target) { printf("GRID MIL %f;\n", GridDist); B.elements(E) { int F=0; if (SkipElements == Yes) { for (int i=0; SkipThisElements[i]!=""; ++i) if (strsub(E.name, 0, strlen(SkipThisElements[i]))==SkipThisElements[i]) F=1; } if ((F==0) && (u2mil(E.x) != snap(E.x) || u2mil(E.y) != snap(E.y))) printf("MOVE %s (%f %f);\n", E.name, snap(E.x), snap(E.y)); } // elements printf("GRID LAST;\n"); } // target } //board exit(ExitCode);