在3D Layout當中的電路板設計。
(圖一) HFSS 3D Layout |
以下程式碼讀取.aedb並輸出trace, polygon的座標訊息,並輸出到json檔案當中
import clr, os, sys, System, json
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()
data = {}
type_group = set()
for i in layout.Primitives:
name = i.GetId()
net = i.GetNet().GetName()
layer = i.GetLayer().GetName()
ptype = i.GetPrimitiveType()
key = ','.join([str(net), str(name), str(layer), str(ptype)])
type_group.add(str(ptype))
data[key]=[]
for p in i.GetPolygonData().Points:
_x = p.X.ToDouble()
_y = p.Y.ToDouble()
if _x == sys.float_info.max or _y == sys.float_info.max:
continue
data[key].append((_x, _y))
sk = sorted(data.keys())
newdata = {str(i):data[i] for i in sk}
print(type_group)
with open('d:/demo/pcb.log', 'w') as f:
json.dump(newdata, f, indent=4)為了要確保抓到的資料是否完整,我們接著到Anaconda Spyder環境當中讀取.json檔的內容並根據座標輸出圖片。注意輸出結果並不包含pads及via的相關結構。
import json
import matplotlib.pyplot as plt
plt.figure(figsize=(30, 20))
with open('d:/demo/pcb.log', 'r') as f:
data = json.load(f)
for i in data:
net, gid, layer, ptype = i.split(',')
if layer == 'PWR':
x, y = zip(*data[i])
plt.fill(list(x)+[x[0]], list(y)+[y[0]], color='r')
plt.savefig('d:/demo/top.png')
plt.show()
(圖二)用Matplotlib繪圖