forked from linmingchih/HowtoSim_Script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRegexMatrixString.py
122 lines (110 loc) · 3.69 KB
/
RegexMatrixString.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 2 10:43:23 2019
@author: mlin
For HFSS and HFSS 3D Layout
"""
import re, clr
clr.AddReference('System.Windows.Forms')
from System.Windows.Forms import Clipboard
import ScriptEnv
ScriptEnv.Initialize("Ansoft.ElectronicsDesktop")
oDesktop.RestoreWindow()
oProject = oDesktop.GetActiveProject()
oDesign = oProject.GetActiveDesign()
oDesktop.ClearMessages("", "", 2)
try:
oModule = oDesign.GetModule("BoundarySetup")
ports=oModule.GetExcitations()[::2]
except:
oModule = oDesign.GetModule("Excitations")
ports=oModule.GetAllPortsList()
AddWarningMessage(str(ports))
x=[(i,j) for i in ports for j in ports]
def TypeA():
match=[]
for i, j in x:
try:
if i==j:
match.append((i,j))
except:
pass
if not match:
AddWarningMessage('No match, Please check condition!')
return None
else:
AddWarningMessage('{} matches!'.format(len(match)))
[AddWarningMessage(str(i)) for i in match]
result=';'.join(['dB(S({},{}))'.format(i,j) for i,j in match])
Clipboard.SetText(result)
def TypeB():
match=[]
for i, j in x:
try:
mi=re.search('_(\d+)_.*S(\d+)', i)
mj=re.search('_(\d+)_.*S(\d+)', j)
if mi.group(1)!=mj.group(1) and mi.group(2)==mj.group(2):
match.append((i,j))
except:
pass
if not match:
AddWarningMessage('No match, Please check condition!')
return None
else:
AddWarningMessage('{} matches!'.format(len(match)))
[AddWarningMessage(str(i)) for i in match]
result=';'.join(['dB(S({},{}))'.format(i,j) for i,j in match])
Clipboard.SetText(result)
def TypeC():
match=[]
for i, j in x:
try:
mi=re.search('_(\d+)_.*S(\d+)', i)
mj=re.search('_(\d+)_.*S(\d+)', j)
if mi.group(1)==mj.group(1) and (mi.group(2),mj.group(2)) in [('3','4'),('7','8'),('9','10'),('14','15')]:
match.append((i,j))
except:
pass
if not match:
AddWarningMessage('No match, Please check condition!')
return None
else:
AddWarningMessage('{} matches!'.format(len(match)))
[AddWarningMessage(str(i)) for i in match]
result=';'.join(['dB(S({},{}))'.format(i,j) for i,j in match])
Clipboard.SetText(result)
def TypeD():
match=[]
for i, j in x:
try:
mi=re.search('_(\d+)_.*S(\d+)', i)
mj=re.search('_(\d+)_.*S(\d+)', j)
if mi.group(1)==mj.group(1) and (mi.group(2),mj.group(2)) in [('3','4'),('7','8'),('9','10'),('14','15')]:
match.append((i,j))
except:
pass
if not match:
AddWarningMessage('No match, Please check condition!')
return None
else:
AddWarningMessage('{} matches!'.format(len(match)))
[AddWarningMessage(str(i)) for i in match]
result=';'.join(['mag(Z({},{}))'.format(i,j) for i,j in match])
Clipboard.SetText(result)
def TypeE():
match=[]
for i, j in x:
try:
if i[-8:]==j[-8:] and i.startswith('BGA') and j.startswith('FCHIP'):
match.append((i,j))
except:
pass
if not match:
AddWarningMessage('No match, Please check condition!')
return None
else:
AddWarningMessage('{} matches!'.format(len(match)))
[AddWarningMessage(str(i)) for i in match]
result=';'.join(['dB(S({},{}))'.format(i,j) for i,j in match])
Clipboard.SetText(result)
TypeE()