summaryrefslogtreecommitdiff
path: root/examples/panelize.py
diff options
context:
space:
mode:
authoropiopan <opiopan@gmail.com>2019-04-01 21:26:26 +0900
committeropiopan <opiopan@gmail.com>2019-04-01 21:26:26 +0900
commitb7320a6b586e8cf12ea126e7ed4320e6d9f53e99 (patch)
treef4cc98eb6642b1b54207c7e25a7e3d33b324ac86 /examples/panelize.py
parent06ba3e68434e7755f1b19c0c7844d1e0f21da4ad (diff)
downloadgerbonara-b7320a6b586e8cf12ea126e7ed4320e6d9f53e99.tar.gz
gerbonara-b7320a6b586e8cf12ea126e7ed4320e6d9f53e99.tar.bz2
gerbonara-b7320a6b586e8cf12ea126e7ed4320e6d9f53e99.zip
add examples
Diffstat (limited to 'examples/panelize.py')
-rwxr-xr-xexamples/panelize.py70
1 files changed, 70 insertions, 0 deletions
diff --git a/examples/panelize.py b/examples/panelize.py
new file mode 100755
index 0000000..1c5c0da
--- /dev/null
+++ b/examples/panelize.py
@@ -0,0 +1,70 @@
+#!/usr/bin/env python
+
+import sys, os
+import gerberex
+from gerberex import DxfFile, GerberComposition, DrillComposition
+
+exts = ['GTL', 'GTO', 'GTP', 'GTS', 'GBL', 'GBO', 'GBP', 'GBS', 'TXT']
+boards=[
+ ('inputs/sonopi-digi.', 0, 0, 0),
+ ('inputs/sonopi-digi.', 0, 22.5, 0),
+ ('inputs/rcstick-f-small.', 0, 60, 0),
+ ('inputs/rcstick-f-small.', 20, 60, 0),
+ ('inputs/rcstick-f-small.', 40, 60, 0),
+ ('inputs/rcstick-f.', 92.216, 55.238, 190),
+ ('inputs/rcstick-jig.', 0, 44, 0),
+ ('inputs/stm32breakout.', 78.0, 59.36, 90),
+ ('inputs/stm32breakout.', 100.0, 59.36, 90),
+]
+outline = 'inputs/outline.dxf'
+mousebites = 'inputs/mousebites.dxf'
+fill = 'inputs/fill.dxf'
+outputs = 'outputs/panelized'
+
+os.chdir(os.path.dirname(__file__))
+try:
+ os.mkdir('outputs')
+except FileExistsError:
+ pass
+
+def putstr(text):
+ sys.stdout.write(text)
+ sys.stdout.flush()
+
+for ext in exts:
+ putstr('merging %s: ' % ext)
+ if ext == 'TXT':
+ ctx = DrillComposition()
+ else:
+ ctx = GerberComposition()
+ for path, x_offset, y_offset, theta in boards:
+ file = gerberex.read(path + ext)
+ file.to_metric()
+ file.rotate(theta)
+ file.offset(x_offset, y_offset)
+ ctx.merge(file)
+ putstr('.')
+ if ext == 'TXT':
+ file = gerberex.read(mousebites)
+ file.draw_mode = DxfFile.DM_MOUSE_BITES
+ file.width = 0.5
+ file.format = (3, 3)
+ ctx.merge(file)
+ else:
+ file = gerberex.read(outline)
+ ctx.merge(file)
+ ctx.dump(outputs + '.' + ext)
+ putstr(' end\n')
+
+putstr('generating GML: ')
+file = gerberex.read(outline)
+file.write(outputs + '.GML')
+putstr('.')
+ctx = GerberComposition()
+file = gerberex.read(fill)
+file.to_metric()
+file.draw_mode = DxfFile.DM_FILL
+ctx.merge(file)
+ctx.dump(outputs + '-fill.GML')
+
+putstr('. end\n')