不同類別的net連接不同數量的原件(IC, R, L, C,...)。訊號線一般是2個,Clock則是兩個到多個,電源net連接的元件數可能多達數十個。GND通常是連接最多元件的net,包含晶片,去耦電容及其他等等。透過讀取這些訊息,可以讓我們對PCB的複雜度有一個初步的了解。以下為程式碼:
import clr, os, sys, System
AnsysEM_Path = 'C:/Program Files/AnsysEM/AnsysEM20.2/Win64/'
sys.path.append(AnsysEM_Path)
os.environ['PATH'] += ';' + AnsysEM_Path
clr.AddReference('Ansys.Ansoft.Edb')
clr.AddReference('Ansys.Ansoft.SimSetupData')
import Ansys.Ansoft.Edb as edb
edb.Database.SetRunAsStandAlone(True)
DB = edb.Database.Open('D:/demo/test.aedb', False)
cell = list(DB.TopCircuitCells)
layout = cell[0].GetLayout()
def getNetInfo(layout):
net_info={}
for n in layout.Nets:
netname=n.GetName()
net_info[netname]={}
for i in n.PadstackInstances:
if len(i.GetName())==0:
continue
try:
net_info[netname][i.GetComponent().GetName()]+=[i.GetName()]
except:
net_info[netname][i.GetComponent().GetName()]=[i.GetName()]
return net_info
netinfo = getNetInfo(layout)
result = []
for i in netinfo:
comps = netinfo[i].keys()
Ucomps = [j for j in comps if j[0] in ['u', 'U']]
NUcomps = [j for j in comps if j[0] not in ['u', 'U']]
sortedcomp = sorted(Ucomps) + sorted(NUcomps)
result.append((len(netinfo[i]), sortedcomp, i))
result.sort()
with open('d:/demo/netinfo.csv', 'w') as f:
for n, comps, net in result:
print(n, comps, net)
f.writelines('{:>4}, {:>32}, {}\n'.format(n, net, comps))
|
(圖一) 輸出按照連接元件數量排序的net name |