-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJLC PCB_SMTA_Exporter.ulp
170 lines (141 loc) · 6.39 KB
/
JLC PCB_SMTA_Exporter.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
Copyright 2019 OXullo Intersecans <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This ULP script was modified by Combinatix to match his JLCPCB-Basic-Parts.lbr
Project home: https://github.com/Combinatix/JLCPCB-Basic-Parts
*/
// Note: the following eagle-bundled ULPs have been used as a guidance:
// * mountsmd.ulp
// * bom.ulp
// * cmd-change-swap-layer.ulp
// * centroid-screamingcircuits-smd.ulp
#usage "<h1>JLCPCB BOM/CPL files generator</h1>\n"
"<h2>Generates BOM and CPL files for JLCPCB SMT assembly service</h2>"
"<a href='https://jlcpcb.com/'>https://jlcpcb.com/</a>"
"<p>Run the ULP from the board editor</p>"
"<author>Author: OXullo Intersecans [email protected]</author>"
"<p>Modified by Combinatix to match his JLCPCB-Basic-Parts.lbr</p>"
"<h3>Project home: <a href='https://github.com/Combinatix/JLCPCB-Basic-Parts'>https://github.com/Combinatix/JLCPCB-Basic-Parts</a></h3>"
// ________________________________________________________________________________________________________________________________
// Globals
int layer_id_map[] = { 1, 16 };
UL_ELEMENT selected_elements[];
string layer_name_map[] = { "Top", "Bottom" };
// ________________________________________________________________________________________________________________________________
// Functions
string intToString(int cislo){
string str = "";
sprintf(str, "%d", cislo);
return str;
}
string replace_commas(string s) { // Convert commas to spaces
while (strstr(s, ",") >= 0) {
string substitution_string = " ";
sprintf(s, "%s%s%s", strsub(s, 0, strstr(s, ",")), substitution_string, strsub(s, strstr(s, ",")+1));
}
return s;
}
// ________________________________________________________________________________________________________________________________
// Main
if (board) board(B) {
// Main procedure
string txt;
int layer_choice = 0;
// Choose Layer
dlgDialog("Layer selection") {
dlgGroup("Export layer") {
dlgRadioButton("&Top", layer_choice);
dlgRadioButton("&Bottom", layer_choice);
}
dlgPushButton("OK") dlgAccept();
};
// Choose Folder - useless
// string output_dir = dlgDirectory("Export files to", filedir(B.name));
// if (output_dir == "") {
// exit(0);
// }
// Loop thru all populated SMD elements
int element_count = 0;
B.elements(E) if (E.populate) {
E.package.contacts(C) {
if (C.smd && C.smd.layer == layer_id_map[layer_choice]) {
selected_elements[element_count++] = E;
break;
}
}
}
// Create File Names
// string base_path = (output_dir + "/" + // Deprecated - Save the mouse clicks, save the planet.
string base_path = (strsub(filename(B.name), 0, strlen(filename(B.name)) - 4) +
"_" + strlwr(layer_name_map[layer_choice]));
string cpl_filename = base_path + "_cpl.csv";
string bom_filename = base_path + "_bom.csv";
// Write CPL file
output(cpl_filename) {
printf("Designator,Mid X,Mid Y,Layer,Rotation\n");
for (int i = 0 ; i < element_count ; ++i) {
UL_ELEMENT E = selected_elements[i];
int angle = E.angle;
// Add attribute rotation correction
E.attributes(A) {
if (A.name == "LCSC_ROTATION_CCW") {
angle = angle + strtol(A.value);
if (angle >= 360){
angle = angle - 360;
}
}
}
// Mirror the part whe bottom layer
if (layer_name_map[layer_choice] == "Bottom") {
angle = (360 - angle);
angle = angle % 360;
}
real ang = angle;
printf("%s,%5.2f,%5.2f,%s,%.1f\n", E.name, u2mm(E.x), u2mm(E.y), layer_name_map[layer_choice], ang);
}
}
// Write BOM file
output(bom_filename) {
int i;
int indexes[];
numeric string values[];
for (i=0 ; i < element_count ; ++i) {
indexes[i] = i;
values[i] = selected_elements[i].value;
}
sort(element_count, indexes, values);
printf("Comment,Designator,Footprint,LCSC Part #\n");
string current_value = "";
string current_footprint = "";
string current_lscpart = "";
string designators = "";
for (i = 0 ; i < element_count ; ++i) {
UL_ELEMENT E = selected_elements[indexes[i]];
if (current_value != "" && (E.value != current_value || E.footprint.name != current_footprint)) {
printf("%s,%s,%s,%s\n", current_value, designators, current_footprint, current_lscpart);
designators = "";
}
if (designators != "") {
designators += " ";
}
designators += E.name;
current_value = replace_commas(E.value);
current_footprint = replace_commas(E.footprint.name);
current_lscpart = "";
E.attributes(A) {
if (A.name == "LCSC_PART") {
current_lscpart = replace_commas(A.value);
}
}
}
if (current_value != "") {
printf("%s,%s,%s,%s\n", current_value, designators, current_footprint, current_lscpart);
}
}
dlgMessageBox("BOM and CPL files have been exported to project folder.");
} else { // if (board) board(B)
dlgMessageBox("!Run this ULP from a Board", "OK");
exit (0);
}