-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathparts2_csv_tex.ulp
250 lines (238 loc) · 7.23 KB
/
parts2_csv_tex.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#usage "<b>Export Partlist from board or schematic to .CSV or .TEX (LATEX -> Longtable)</b>\n"
"<p>This ULP generates either a .csv table (Microsoft-Excel or OpenOffice-Calc) or a .tex table (LaTeX, as \"Longtable\") for documentation purpose.<br>"
"<br>You can select, if your table should contain a consecutive number, name, value, package and/or library. "
"This ULP can be started either from a schematic or from the board as long as the appropriate files exist."
"<br><br>Version 0.01</p>"
"<author>Author: Matthias Meeh, 08/2009</author>"
// *************************************************************************************
// THIS PROGRAM IS PROVIDED AS IS AND WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED
// *************************************************************************************
// ********* global variables ************
int type_out;
int contents_01 = 1;
int contents_02 = 1;
int contents_03 = 1;
int contents_04 = 1;
int contents_05 = 1;
// ********* replace secific character - only for ".tex" files required ************
string check(string checkstring){
string newstring = "";
int i = 0, add = 0, length_chkstr = 0, b_exit = 0;
length_chkstr = strlen(checkstring);
if (checkstring == "")
return (newstring = " n.a.");
for (i=0;i<length_chkstr;i++){
switch (checkstring[i]){
case '$':
case '_':
newstring[i+add] = 0x5C; add++;
newstring[i+add] = checkstring[i];
break;
case '²':
newstring[i+add] = '2';
break;
case 0xB5:
newstring[i+add] = '$'; add++;
newstring[i+add] = 0x5C; add++;
newstring[i+add] = 'm'; add++;
newstring[i+add] = 'u'; add++;
newstring[i+add] = '$';
break;
default:
newstring[i+add] = checkstring[i];
}
}
newstring[i+add] = 0;
return newstring;
}
// ********* generate data list ************
void generate_list(void){
if (type_out == 0){
int i = 0;
project.board(B) {
string fileName = dlgFileSave("Save File", filesetext(B.name, ".csv"), "*.csv");
if (fileName == "")
exit(0);
output(fileName) {
printf("Bauteilliste für %s\n", B.name);
if (contents_01){
printf("No.:");
if ((contents_02)||(contents_03)||(contents_04)||(contents_05))
printf("\;");
}
if (contents_02){
printf("Name:");
if ((contents_03)||(contents_04)||(contents_05))
printf("\;");
}
if (contents_03){
printf("Value:");
if ((contents_04)||(contents_05))
printf("\;");
}
if (contents_04){
printf("Package:");
if (contents_05)
printf("\;");
}
if (contents_05)
printf("Library:");
B.elements(E) {
if (contents_01)
printf("\n%d\;",++i);
if (contents_02)
printf("%s\;", E.name);
if (contents_03){
if (E.value == "")
printf(" ---\;");
else
printf("%s\;", E.value);
}
if (contents_04)
printf("%s\;", E.package.name);
if (contents_05)
printf("%s\;", E.package.library);
}
}
}
exit(0);
}
if (type_out == 1){
int i = 0;
string temp;
project.board(B) {
string fileName = dlgFileSave("Save File", filesetext(B.name, ".tex"), "*.tex");
if (fileName == "")
exit(0);
output(fileName) {
printf("%% \*\*\*\*\*\*\*\*\*\* Eagle ULP \"parts2_csv_tex.ulp\", by Matthias Meeh, 2009 \*\*\*\*\*\*\*\*\*\*\n");
printf("\n%% Include this statement in your config file: \n");
printf("%%\\usepackage\{longtable\}\n");
printf("\n%% Use this statement at desired postion: \n");
printf("%%\\input\{"); printf(fileName); printf("\} \n\n");
printf("\\begin\{longtable\} \{");
if (contents_01)
printf("p\{1cm\} ");
if (contents_02)
printf("p\{2cm\} ");
if (contents_03)
printf("p\{3cm\} ");
if (contents_04)
printf("p\{4cm\} ");
if (contents_05)
printf("p\{2.5cm\} ");
printf("\}\n");
printf(" \\hline ");
if (contents_01){
printf("No.");
if ((contents_02)||(contents_03)||(contents_04)||(contents_05))
printf(" \&");
}
if (contents_02){
printf("Name");
if ((contents_03)||(contents_04)||(contents_05))
printf(" \&");
}
if (contents_03){
printf("Value");
if ((contents_04)||(contents_05))
printf(" \&");
}
if (contents_04){
printf("Package");
if (contents_05)
printf(" \&");
}
if (contents_05)
printf("Library");
printf(" \\\\ \\hline \\endfirsthead\n");
printf(" \\hline ");
if (contents_01){
printf("No.");
if ((contents_02)||(contents_03)||(contents_04)||(contents_05))
printf(" \&");
}
if (contents_02){
printf("Name");
if ((contents_03)||(contents_04)||(contents_05))
printf(" \&");
}
if (contents_03){
printf("Value");
if ((contents_04)||(contents_05))
printf(" \&");
}
if (contents_04){
printf("Package");
if (contents_05)
printf(" \&");
}
if (contents_05)
printf("Library");
printf(" \\\\ \\hline \\endhead\n");
printf(" \\hline \\multicolumn\{%d\}\{c\}\{\\textit\{Continue on next page\}\}\\\\ \\hline \\endfoot\n", (contents_01+contents_03+contents_03+contents_04+contents_05));
printf(" \\endlastfoot\n");
B.elements(E) {
if (contents_01){
printf(" %d", ++i);
if ((contents_02)||(contents_03)||(contents_04)||(contents_05))
printf(" \&");
}
if (contents_02){
printf(" %s", check (E.name));
if ((contents_03)||(contents_04)||(contents_05))
printf(" \&");
}
if (contents_03){
printf(" %s", check (E.value));
if ((contents_04)||(contents_05))
printf(" \&");
}
if (contents_04){
printf(" %s", check (E.package.name));
if ((contents_05))
printf(" \&");
}
if (contents_05)
printf(" %s", check (E.package.library));
printf("\\\\\n");
}
printf(" \\hline\n");
printf(" \\caption\{Part List for %s\}\\\\\n", check(B.name));
printf("\\end\{longtable\}\n");
printf("\n\n");
}
}
exit(0);
}
}
// ********* dlg-Box for data type selection ************
dlgDialog("Export as:") {
dlgGroup("Select Contents:") {
dlgCheckBox("&Consecutive Number", contents_01);
dlgCheckBox("&Name", contents_02);
dlgCheckBox("&Value", contents_03);
dlgCheckBox("&Package", contents_04);
dlgCheckBox("&Library", contents_05);
}
dlgHBoxLayout {
dlgGroup("Output file") {
dlgRadioButton(".&csv (Excel,Calc,...)", type_out);
dlgRadioButton(".&tex (LaTeX)", type_out);
}
}
dlgHBoxLayout {
dlgPushButton("Cr&eate"){
if ((contents_01)||(contents_02)||(contents_03)||(contents_04)||(contents_05)){
generate_list();
}
else{
dlgMessageBox(";You must select at least one contents item!");
}
}
dlgPushButton("C&ancel"){
exit(0);
}
}
};
// Ich habe fertig :-)