Last active
October 10, 2015 08:03
-
-
Save RaD/379eb44d7452f9ed77f4 to your computer and use it in GitHub Desktop.
PCB panelization script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #usage "<b>Generate name layers to panelize board</b>\n" | |
| "<p>" | |
| "Generates a command sequence which copies the name texts (support spin-flag) " | |
| "of all elements of your layout into newly generated layers (125 and 126). " | |
| "After running the ULP you can GROUP, CUT and PASTE your layout " | |
| "to get an array of several boards. Make sure all layers are displayed before." | |
| "<p>" | |
| "The duplicated name texts in the new layers will not be changed. " | |
| "Please notice that you have to deactivate layers 25 and 26 if you use " | |
| "the CAM processor e.g. for generating gerber data. Instead, you have to activate " | |
| "the new layers 125 and 126. Thus you get an identical silk screen for all " | |
| "your layouts in this array." | |
| "<p>" | |
| "<b>Texts must be SMASHed before we can duplicate them!</b> " | |
| "<p>" | |
| "<author>Author: [email protected]</author>" | |
| // THIS PROGRAM IS PROVIDED AS IS AND WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED | |
| #require 4.1106; | |
| // 6.12.2004 Text with Spin-Flag [email protected] | |
| // 28.06.2006 accept Sigle-Quote on end of name of element [email protected] | |
| int offset = 100; | |
| string tcolor = "yellow"; | |
| string bcolor = "magenta"; | |
| int used_name_layers[]; | |
| string used_name_[]; | |
| string cmd_header; | |
| string cmd = "\nSET UNDO_LOG OFF;\nGRID MIL;\n"; // advisable for speed reasons | |
| string h; | |
| string check_single_quote(string s) { // 2006.06.28 | |
| int l = strlen(s); | |
| if (s[l-1] == '\'') s+="'"; | |
| return s; | |
| } | |
| void test(void) { | |
| string txt = "Used Layers for >NAME\n"; | |
| for (int n = 0; n < 256; n++) { | |
| if(used_name_layers[n]) { | |
| sprintf(h, "Layer %3d count %d\t%s\n", n, used_name_layers[n], used_name_[n]); | |
| txt += h; | |
| } | |
| } | |
| if (dlgMessageBox(txt, "OK", "Cancel") != 0) exit(-1); | |
| return; | |
| } | |
| void header(void) { | |
| for (int n = 0; n < 256; n++) { | |
| if(used_name_layers[n]) { | |
| sprintf(h, "layer %d _%s;\n", n + offset, used_name_[n]); | |
| cmd_header += h; | |
| if (n & 1) sprintf(h, "set color_layer %d %s;\n", n + offset, tcolor); | |
| else sprintf(h, "set color_layer %d %s;\n", n + offset, bcolor); | |
| cmd_header += h; | |
| } | |
| } | |
| } | |
| void Text(string Ename, int Tlayer, int Tx, int Ty, int Tsize, real Tangle, int Tratio, int Tmirror, int Tspin, int Tfont, int Talign) { | |
| string text_font[] = {"vector", "proportional", "fixed"}; | |
| string text_align[] = {"bottom left", "bottom center", "bottom right", | |
| "center left", "center", "center right", | |
| "top left", "top center", "top right"}; | |
| sprintf(h, "Change Layer %d;\n", Tlayer + offset); | |
| cmd += h; | |
| sprintf(h, "Change Size %5.3f;\n", u2mil(Tsize)); | |
| cmd += h; | |
| sprintf(h, "Change Ratio %d;\n", Tratio); | |
| cmd += h; | |
| sprintf(h, "Change Font %s;\n", text_font[Tfont]); | |
| cmd += h; | |
| sprintf(h, "Change Align %s;\n", text_align[Talign]); | |
| cmd += h; | |
| string mirr, spin; | |
| if (Tmirror) mirr = "M"; | |
| else mirr = ""; | |
| if (Tspin) spin = "S"; | |
| else spin = ""; | |
| sprintf(h, "Text '%s' %s%sR%.1f (%5.3f %5.3f);\n", check_single_quote(Ename), spin, mirr, Tangle, u2mil(Tx), u2mil(Ty)); | |
| cmd += h; | |
| return; | |
| } | |
| if (board) { | |
| board(B) { | |
| B.layers(L) { | |
| used_name_[L.number] = L.name; | |
| } | |
| header(); | |
| B.elements(E) { // smashed texts | |
| E.texts(T) { | |
| if (T.value == E.name) { | |
| used_name_layers[T.layer]++; | |
| Text(E.name, T.layer, T.x, T.y, T.size, T.angle, T.ratio, T.mirror, T.spin, T.font, T.align); | |
| } | |
| } | |
| E.package.texts(T) { // unsmashed texts | |
| if (T.value == E.name) { | |
| used_name_layers[T.layer]++; | |
| Text(E.name, T.layer, T.x, T.y, T.size, T.angle, T.ratio, T.mirror, T.spin, T.font, T.align); | |
| } | |
| } | |
| } | |
| } | |
| // test(); | |
| cmd += "SET UNDO_LOG ON;\nGRID LAST;\n"; | |
| header(); | |
| cmd_header += cmd; | |
| cmd = cmd_header; | |
| // EditBox | |
| int Result = dlgDialog("Descriptions") { | |
| dlgHBoxLayout { | |
| dlgVBoxLayout { dlgSpacing(500); } | |
| dlgTextEdit(cmd); | |
| } | |
| dlgHBoxLayout { | |
| dlgPushButton("+Execute") dlgAccept(); | |
| dlgSpacing(100); | |
| dlgPushButton("-Cancel") dlgReject(); | |
| } | |
| }; | |
| if (Result == 0) exit(0); | |
| exit(cmd); | |
| } | |
| else { | |
| dlgMessageBox("\n Start this ULP in a Board \n"); | |
| exit (0); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment