forked from linmingchih/HowtoSim_Script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_comp_on_ports.py
69 lines (63 loc) · 1.97 KB
/
add_comp_on_ports.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import ScriptEnv
ScriptEnv.Initialize("Ansoft.ElectronicsDesktop")
oDesktop.RestoreWindow()
oProject = oDesktop.GetActiveProject()
oDesign = oProject.GetActiveDesign()
oEditor = oDesign.SetActiveEditor("SchematicEditor")
def cutpaste(port, x, y, angle):
oEditor.Cut(
[
"NAME:Selections",
"Selections:=" , [port]
])
oEditor.Paste(
[
"NAME:Attributes",
"Page:=" , 1,
"X:=" , x,
"Y:=" , y,
"Angle:=" , angle,
"Flip:=" , False
])
def addres(x,y,angle):
oEditor.CreateComponent(
[
"NAME:ComponentProps",
"Name:=" , "Nexxim Circuit Elements\\Resistors:RES_",
"Id:=" , "6"
],
[
"NAME:Attributes",
"Page:=" , 1,
"X:=" , x,
"Y:=" , y,
"Angle:=" , angle,
"Flip:=" , False
])
scale=2.54e-5
x=[i for i in oEditor.GetSelections() if i.startswith('IPort')]
AddWarningMessage(str(x))
for port in x:
a=oEditor.GetPropertyValue("BaseElementTab", port, "Component Angle")
angle=a[:-1]
loc=oEditor.GetPropertyValue("BaseElementTab", port, "Component Location")
x,y=[i.strip()[:-3] for i in loc.split(',')]
x,y=int(x), int(y)
if angle=='0':
AddWarningMessage(port)
cutpaste(port, x*scale, (y+500)*scale,0)
addres(x*scale, (y+200)*scale,90)
if angle=='180':
AddWarningMessage(port)
cutpaste(port, x*scale, (y-500)*scale,0)
addres(x*scale, (y-200)*scale,90)
if angle=='90':
AddWarningMessage(port)
cutpaste(port, (x-500)*scale, y*scale,0)
addres((x-200)*scale, y*scale,0)
if angle=='270':
AddWarningMessage(port)
cutpaste(port, (x+500)*scale, y*scale,0)
addres((x+200)*scale, y*scale,0)
else:
pass