-
Notifications
You must be signed in to change notification settings - Fork 1
/
action_menu_arrange_like_schematic.py
48 lines (42 loc) · 1.39 KB
/
action_menu_arrange_like_schematic.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import pcbnew
import re
import datetime
import json
import Tkinter
from tkFileDialog import askopenfilename
class ArrangeLikeSchematic(pcbnew.ActionPlugin):
def defaults( self ):
self.name = "Arrange like schematic"
self.category = "Modify PCB"
self.description = "Arrange components so that layout is similar to schematic"
def get_sch_filename(self):
root = Tkinter.Tk()
root.update()
filename = askopenfilename(
initialdir = "~",
title = "Select file",
filetypes = (("sch files","*.sch"),("all files","*.*")),
)
root.update()
root.destroy()
root.mainloop()
return filename
def get_component_positions(self, fn):
import sch
positions = {}
s = sch.Schematic(fn)
for c in s.components:
ref = c.labels['ref']
positions[ref] = c.position
return positions
def Run( self ):
fn = self.get_sch_filename()
positions = self.get_component_positions(fn)
pcb = pcbnew.GetBoard()
components = pcb.GetModules()
for c in components:
ref = c.GetReference()
if ref in positions:
x, y = int(positions[ref]['posx'])*25.4/1000, int(positions[ref]['posy'])*25.4/1000
c.SetPosition(pcbnew.wxPointMM(x, y))
ArrangeLikeSchematic().register()