Skip to content

Instantly share code, notes, and snippets.

@hsgw
Created April 23, 2020 12:10
Show Gist options
  • Save hsgw/6efe82e336203e8d483e43bdc23bca64 to your computer and use it in GitHub Desktop.
Save hsgw/6efe82e336203e8d483e43bdc23bca64 to your computer and use it in GitHub Desktop.
import json
import pcbnew
with open('out.json') as file:
points = json.load(file)
print("load {} points from json".format(len(points)))
modules = pcbnew.GetBoard().GetModules()
for m in modules:
if "SW_MX" in m.GetReference():
no = int(m.GetReference()[5:])-1
if no < len(points):
print("SW_MX{} : {}, {}").format(no, points[no][1], points[no][2])
pos = pcbnew.wxPointMM(points[no][1], points[no][2])
m.SetPosition(pos)
import dxfgrabber
import json
from operator import itemgetter
dxf = dxfgrabber.readfile("keyboard.dxf")
# points = [entity.point for entity in dxf.entities if isinstance(entity, dxfgrabber.dxfentities.Point)]
points = [(int(entity.text), entity.insert[0], entity.insert[1]*-1) for entity in dxf.entities if isinstance(entity, dxfgrabber.dxfentities.Text)]
points.sort(key=itemgetter(0))
num = 1
ref = "SW_MX"
for point in points:
print('SW{} {}, {}'.format(point[0], point[1], point[2]))
num += 1
print('Found {} points'.format(len(points)))
with open('out.json', 'w') as file:
json.dump(points, file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment