Skip to content

Instantly share code, notes, and snippets.

@sash13
Last active September 7, 2020 14:15
Show Gist options
  • Save sash13/30f248fa224d21c9d90aa1e81bc56c17 to your computer and use it in GitHub Desktop.
Save sash13/30f248fa224d21c9d90aa1e81bc56c17 to your computer and use it in GitHub Desktop.
Eagle *.mnt to Pick and Place SMT .txt (Altium, etc) file converter
from texttable import Texttable
import csv
import re
import sys
PP_header = ['Designator', 'Comment', 'Layer', 'Footprint', 'Center-X(mm)', 'Center-Y(mm)', 'Rotation', 'Description']
PP_header_gerbv = ['ref', 'package', 'val', 'pos_x', 'pos_y', 'rot', 'layer'] #https://repo.or.cz/ruwai.git/blob/HEAD:/software/python/kicad_util/rw_pnp_map_from_pos.py#l80
PP_align = ['l'] * len(PP_header)
COMP_NAME = 0
COMP_VALUE = 4
COMP_SIZE = 5
COMP_ANGLE = 3
COMP_X_POS = 1
COMP_Y_POS = 2
def toSMD(name):
pattern = re.compile('[CRLM]\d{4,5}')
m = pattern.match(name)
if m:
return 'SMD' + ''.join(name[1:])
return name
def main(f_name):
with open(f_name) as file:
reader = csv.reader(file, delimiter=' ', skipinitialspace=True)
table = Texttable()
table.set_cols_align(PP_align)
table.set_deco(0)
table.set_max_width(0)
table_rows = []
table_rows.append(PP_header)
table_rows_gerbv = []
table_rows_gerbv.append(PP_header_gerbv)
for row in reader:
table_rows.append([row[COMP_NAME], row[COMP_VALUE], 'TopLayer', toSMD(row[COMP_SIZE]),
row[COMP_X_POS], row[COMP_Y_POS], row[COMP_ANGLE], '""'])
table_rows_gerbv.append([row[COMP_NAME], toSMD(row[COMP_SIZE]), row[COMP_VALUE],
float(row[COMP_X_POS])*1/25.4 * 1000, float(row[COMP_Y_POS])*1/25.4 * 1000, float(row[COMP_ANGLE])*-1, 'top'])
table.add_rows(table_rows)
print(table.draw())
with open(f_name.split('.')[0]+'_pickPlace.txt', "w") as out_file:
out_file.write(table.draw())
out_file_gerbv = open(f_name.split('.')[0]+'_pickPlace_gerbv.csv', 'w')
out_writer = csv.writer(out_file_gerbv, lineterminator='\n', delimiter=',', quoting=csv.QUOTE_MINIMAL)
out_writer.writerows(table_rows_gerbv)
out_file_gerbv.close()
if __name__ == '__main__':
main(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment