mirror of
https://github.com/jhbruhn/eurorack.git
synced 2025-03-14 18:55:48 +00:00
Replace bomtool and mnbtool with ulp script
This commit is contained in:
parent
9ce28e066d
commit
d9fe563e40
3 changed files with 137 additions and 83 deletions
|
@ -1,44 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
# coding=utf8
|
||||
|
||||
import sys
|
||||
import csv
|
||||
from collections import OrderedDict
|
||||
|
||||
package_remap = {
|
||||
"R0603": "0603_R",
|
||||
"C0603": "0603_C",
|
||||
"R0402": "0402_R",
|
||||
"C0402": "0402_C",
|
||||
"SO08": "SOIC-8_150mil",
|
||||
"SO14": "SOIC-14_150MIL"
|
||||
}
|
||||
|
||||
value_remap = {
|
||||
"TL072D": "TL072",
|
||||
"TL074D": "TL074",
|
||||
"1N4148-2": "1N4148"
|
||||
}
|
||||
|
||||
in_file = open(sys.argv[1], 'r')
|
||||
out_file = open(sys.argv[2], 'w')
|
||||
|
||||
reader = csv.DictReader(in_file, delimiter=';')
|
||||
ordered_fieldnames = OrderedDict([('Comment', None), ('Designator', None), ('Footprint', None), ('LCSC Part #', None), ('LCSC Part Type', None)])
|
||||
writer = csv.DictWriter(out_file, delimiter=',', quoting=csv.QUOTE_NONNUMERIC, fieldnames=ordered_fieldnames)
|
||||
|
||||
writer.writerow({'Comment': 'Comment', 'Designator': 'Designator', 'Footprint': 'Footprint', 'LCSC Part #': 'LCSC Part #', 'LCSC Part Type': 'LCSC Part Type'})
|
||||
|
||||
for row in reader:
|
||||
names, value, package, num = [row['Parts'], row['Value'], row['Package'], row['Qty']]
|
||||
package = package_remap.get(package, package)
|
||||
value = value_remap.get(value, value)
|
||||
namestring = ""
|
||||
for name in names.split(','):
|
||||
name = name.strip()
|
||||
namestring += name+ ', '
|
||||
namestring = namestring[:len(namestring) - 2]
|
||||
writer.writerow({'Comment': value, 'Designator': namestring, 'Footprint': package, 'LCSC Part #': '', 'LCSC Part Type': ''})
|
||||
|
||||
in_file.close()
|
||||
out_file.close()
|
137
helpers/jlcpcb_smta_exporter.ulp
Normal file
137
helpers/jlcpcb_smta_exporter.ulp
Normal file
|
@ -0,0 +1,137 @@
|
|||
/*
|
||||
|
||||
Copyright 2019 OXullo Intersecans <x@brainrapers.org>
|
||||
|
||||
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.
|
||||
|
||||
*/
|
||||
|
||||
// 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 "<b>JLCPCB BOM/CPL files generator</b>\n"
|
||||
"<p>"
|
||||
"Generates BOM and CPL files for JLCPCB SMT assembly service"
|
||||
"https://jlcpcb.com/smt-assembly"
|
||||
"<p>"
|
||||
"Run the ULP from the board editor"
|
||||
"<p>"
|
||||
"<author>Author: OXullo Intersecans x@brainrapers.org</author>"
|
||||
|
||||
|
||||
int layer_id_map[] = { 1, 16 };
|
||||
UL_ELEMENT selected_elements[];
|
||||
string layer_name_map[] = { "Top", "Bottom" };
|
||||
|
||||
if (board) board(B) {
|
||||
|
||||
string txt;
|
||||
int layer_choice = 0;
|
||||
|
||||
dlgDialog("Layer selection") {
|
||||
dlgGroup("Export layer") {
|
||||
dlgRadioButton("&Top", layer_choice);
|
||||
dlgRadioButton("&Bottom", layer_choice);
|
||||
}
|
||||
dlgPushButton("OK") dlgAccept();
|
||||
};
|
||||
|
||||
string output_dir = dlgDirectory("Export files to", filedir(B.name));
|
||||
|
||||
if (output_dir == "") {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string base_path = (output_dir + "/" +
|
||||
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";
|
||||
|
||||
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;
|
||||
if (layer_name_map[layer_choice] == "Bottom") {
|
||||
angle = (360 - angle);
|
||||
angle = angle + 180;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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 = E.value;
|
||||
current_footprint = E.footprint.name;
|
||||
current_lscpart = "";
|
||||
|
||||
E.attributes(A) {
|
||||
if (A.name == "LCSC_PART") {
|
||||
current_lscpart = A.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("%s,%s,%s,%s\n", current_value, designators, current_footprint, current_lscpart);
|
||||
}
|
||||
|
||||
dlgMessageBox("BOM and CPL files have been exported to: " + output_dir, "OK");
|
||||
|
||||
} else {
|
||||
dlgMessageBox("Run this ULP from a Board", "OK");
|
||||
exit (0);
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
# coding=utf8
|
||||
|
||||
import sys
|
||||
import csv
|
||||
from collections import OrderedDict
|
||||
|
||||
in_t_file = open(sys.argv[1], 'r')
|
||||
in_b_file = open(sys.argv[2], 'r')
|
||||
out_file = open(sys.argv[3], 'w')
|
||||
|
||||
reader_t = csv.reader(in_t_file, dialect='excel-tab')
|
||||
reader_b = csv.reader(in_b_file, dialect='excel-tab')
|
||||
ordered_fieldnames = OrderedDict(
|
||||
[('Designator', None), ('Mid X', None), ('Mid Y', None), ('Layer', None), ('Rotation', None)])
|
||||
writer = csv.DictWriter(out_file, delimiter=',',
|
||||
quoting=csv.QUOTE_NONNUMERIC, fieldnames=ordered_fieldnames)
|
||||
|
||||
writer.writerow({'Designator': 'Designator', 'Mid X': 'Mid X',
|
||||
'Mid Y': 'Mid Y', 'Layer': 'Layer', 'Rotation': 'Rotation'})
|
||||
|
||||
|
||||
for reader in [reader_t, reader_b]:
|
||||
layer = 'Top'
|
||||
if reader == reader_b:
|
||||
layer = 'Bottom'
|
||||
|
||||
for row in reader:
|
||||
row = list(filter(None, row[0].split(' ')))
|
||||
rotation = int(row[3])
|
||||
if layer == 'Bottom':
|
||||
rotation = (360 - rotation + 180) % 360
|
||||
|
||||
writer.writerow({'Designator': row[0], 'Mid X': row[1],
|
||||
'Mid Y': row[2], 'Layer': layer, 'Rotation': rotation})
|
||||
|
||||
in_t_file.close()
|
||||
in_b_file.close()
|
||||
out_file.close()
|
Loading…
Reference in a new issue