-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcomponent_instances.py
55 lines (42 loc) · 1.71 KB
/
component_instances.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
49
50
51
52
53
54
55
#!/usr/bin/python
import json
def upvComponentInstances(upv_component_instances, bounds):
"""
Component Instances
Actual footprints placed on PCB, references upvComponent
"""
count = 0
used_count = 0
component_instances = {}
for component_instance in upv_component_instances:
count += 1
if ('footprint_pos' in component_instance) == True:
used_count += 1
name = component_instance['attributes']['refdes']
bounding_box_x = bounds['max_x'] - bounds['min_x']
translate_x = bounds['min_x']
translate_x += bounding_box_x / 2
bounding_box_y = bounds['max_y'] - bounds['min_y']
translate_y = bounds['min_y']
translate_y += bounding_box_y / 2
location = [nmToMm(component_instance['footprint_pos']['x'] - translate_x), nmToMm(component_instance['footprint_pos']['y'] - translate_y)]
silkscreen = {
'refdef': {
'location': [0, 2],
'rotate': 0,
'show': True
}
}
data = {
'footprint': component_instance['library_id'],
'layer': component_instance['footprint_pos']['side'],
'location': location,
'rotate': component_instance['footprint_pos']['rotation'] * 180,
'show': True,
'silkscreen': silkscreen
}
component_instances[name] = data
print(used_count, "component instances processed of", count)
return(component_instances)
def nmToMm(nm):
return (int(nm) / 1000000)