Skip to content

Commit

Permalink
Add export for pick & place machines.
Browse files Browse the repository at this point in the history
Based on 'mountsmd.ulp' distributed with Eagle.
  • Loading branch information
avian2 committed Nov 6, 2013
1 parent 5072cb7 commit 727c90d
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 2 deletions.
2 changes: 2 additions & 0 deletions eagle_automation/config.py
@@ -1,6 +1,7 @@
LAYERS = {
'topassembly': {
'layers': ['tPlace', 'tNames', 'tDocu'],
'pp_id': 1,
},

'topsilk': {
Expand Down Expand Up @@ -42,6 +43,7 @@
'bottomassembly': {
'layers': ['bPlace', 'bNames', 'bDocu'],
'mirror': True,
'pp_id': 16,
},

'outline': {
Expand Down
85 changes: 85 additions & 0 deletions eagle_automation/export.py
Expand Up @@ -32,6 +32,11 @@ def export(self, in_path, layers, out_paths):
cmd = [EAGLE, "-C" + script_string, in_path]
subprocess.call(cmd)

self.clean()

def clean(self):
pass

class EaglePNGExport(EagleScriptExport):
def write_script(self, extension, layers, out_paths):

Expand Down Expand Up @@ -79,6 +84,86 @@ def write_script(self, extension, layers, out_paths):

return script

class EagleMountSMDExport(EagleScriptExport):

# Following ULP code based on "mountsmd.ulp" by CadSoft

ULP_TEMPLATE_HEAD = """
board(B) {
string fileName;
"""

ULP_TEMPLATE = """
fileName = "%(out_path)s";
output(fileName) {
B.elements(E) {
int wasSmd,
xmax =-2147483648,
xmin = 2147483647,
ymax = xmax,
ymin = xmin;
wasSmd = 0;
E.package.contacts(C) {
if (C.smd && C.smd.layer == %(pp_id)d) {
wasSmd = 1;
if (C.x > xmax) xmax = C.x;
if (C.y > ymax) ymax = C.y;
if (C.x < xmin) xmin = C.x;
if (C.y < ymin) ymin = C.y;
}
}
if (wasSmd)
printf("%%s %%5.2f %%5.2f %%3.0f %%s %%s\\n",
E.name, u2mm((xmin + xmax)/2), u2mm((ymin + ymax)/2),
E.angle, E.value, E.package.name);
}
}
"""

ULP_TEMPLATE_TAIL = """
}
"""

def write_script(self, extension, layers, out_paths):

if extension != 'brd':
raise BadExtension

self.ulp_dir = self.workdir or tempfile.mkdtemp()
self.ulp_path = os.path.join(self.ulp_dir, "export.ulp")

ulp = open(self.ulp_path, "w")
ulp.write(self.ULP_TEMPLATE_HEAD)

for layer, out_path in zip(layers, out_paths):

pp_id = layer['pp_id']

assert '"' not in out_path
ulp.write(self.ULP_TEMPLATE % {
'out_path': out_path,
'pp_id': pp_id
})

ulp.write(self.ULP_TEMPLATE_TAIL)
ulp.close()

print self.ulp_path

return [ "DISPLAY ALL",
"RUN %s" % (self.ulp_path,) ]

def clean(self):
os.unlink(self.ulp_path)
if not self.workdir:
os.rmdir(self.ulp_dir)

class EagleCAMExport:
def __init__(self, workdir=None):
pass
Expand Down
6 changes: 4 additions & 2 deletions eagleexport
Expand Up @@ -5,13 +5,15 @@ from eagle_automation.config import *
from eagle_automation.export import EaglePNGExport, \
EaglePDFExport, \
EagleGerberExport, \
EagleExcellonExport
EagleExcellonExport, \
EagleMountSMDExport
import sys

out_types = { 'png': EaglePNGExport,
'pdf': EaglePDFExport,
'gerber': EagleGerberExport,
'excellon': EagleExcellonExport }
'excellon': EagleExcellonExport,
'mountsmd': EagleMountSMDExport }

def usage():
print """eagleexport, export layers from CadSoft Eagle files
Expand Down

0 comments on commit 727c90d

Please sign in to comment.