-
Notifications
You must be signed in to change notification settings - Fork 2
/
gen-brd-variants.ulp
64 lines (56 loc) · 2.56 KB
/
gen-brd-variants.ulp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#usage "<b>Save variant board files.</b>"
"<p>"
"RUN save-brd-variants.ulp"
"<p>"
"Switches through all main assembly variants and saves a board file for each variant with name<br>"
"<i>filename-variantname.brd</i>. For the default assembly variant <i>default</i> is used as variant name.<br>"
"Schematic and board have to be loaded and be in a consistent state.<br>"
"This is useful as a preparatory step for CAM processing of the variants.<br>"
"If the variant name contains characters which are invalid for file names, a '_' is inserted instead.<br>"
"Invalid characters are /\\:<>*|?."
"<p>"
"<author>author [email protected]</author>"
#require 6.0500;
string Version = "1.0";
// Duplicate the apostroph: Needed for EAGLE commands with arguments with apostrophs allowed
string DupApostroph(string name) {
string t[];
int cnt = strsplit(t, name, '\'');
if (cnt > 1) {
name = "";
for (int i = 0; i < cnt; ++i)
if (i == 0)
name += t[i];
else
name += "''" + t[i];
}
return name;
}
// Main section
if (project.schematic && project.board)
project.schematic(SCH) {
string cmds, line, info;
string invalidChars = "/\\:<>*|?"; // Chars in variant names that create problems.
info = "Creating variant board files\n\n";
// Currently selected variant. Default variant: The name "''" is disturbing here...
string currVar = (variant() == "''") ? "" : variant();
SCH.variantdefs(VD) {
string varName = (VD.name == "''") ? "default" : VD.name;
// Replace chars which are invalid for filenames with '_'
char ic = invalidChars[0];
for (int i = 0; ic != 0; ic = invalidChars[++i])
for (int pos = strchr(varName, ic); pos != -1; pos = strchr(varName, ic))
varName = strsub(varName, 0, pos) + "_" + strsub(varName, pos + 1);
string fileName = filesetext(SCH.name, "-" + varName + ".brd");
// switch to variant in SCH and write the BRD. "SET CONFIRM NO" in order to confirm question "Do you want to save SCH as well" with no.
sprintf(line, "EDIT .sch; VARIANT '%s'; EDIT .brd; SET CONFIRM NO; WRITE '%s';\n",
(VD.name == "''" ? "" : DupApostroph(VD.name)), DupApostroph(fileName));
cmds += line;
info += fileName + "\n";
}
sprintf(line, "EDIT .sch; VARIANT '%s'; WRITE;\n", DupApostroph(currVar)); // switch back to current variant
cmds += line;
exit(cmds);
}
else
dlgMessageBox("No consistent schematic/board pair! ", "Ok");