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:/demo4/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
def getComponentInfo(layout):
comp_info=[]
for c in layout.Groups:
x = ( c.GetName(),
c.GetComponentDef().GetName(),
c.GetComponentType().ToString(),
c.GetNumberOfPins(),
c.GetPlacementLayer().GetName(),
)
comp_info.append(x)
return comp_info
def get_layer_roughness(layer):
roughness_info={}
region_type = { 'Top': edb.Cell.RoughnessModel.Region.Top,
'Bottom': edb.Cell.RoughnessModel.Region.Bottom,
'Side': edb.Cell.RoughnessModel.Region.Side}
for i in region_type:
model = layer.GetRoughnessModel(region_type[i])
roghness_name = type(model).__name__
if roghness_name == 'HurrayRoughnessModel':
roughness_info[i] = ('HurrayRoughnessModel', float(model.NoduleRadius), float(model.SurfaceRatio))
elif roghness_name == 'GroisseRoughnessModel':
roughness_info[i] = ('GroisseRoughnessModel', float(model.Roughness))
else:
pass
return roughness_info
def getStackupInfo(layout):
lc = layout.GetLayerCollection()
layer_info = []
for i in lc.Layers(edb.Cell.LayerTypeSet.AllLayerSet):
if i.IsStackupLayer():
x = (i.GetName(),
i.GetThickness(),
i.GetMaterial(),
i.GetFillMaterial(),
i.IsRoughnessEnabled(),
float(i.GetEtchFactor()),
get_layer_roughness(i)
)
layer_info.append(x)
return layer_info
def getMaterialInfo(database):
material_info={}
for i in database.MaterialDefs:
for p in i.GetAllProperties():
if p.ToString().isnumeric():
continue
v = clr.Reference[float]()
i.GetProperty(p, v)
try:
material_info[i.GetName()] += [(p.ToString(), v.ToString())]
except:
material_info[i.GetName()] = [(p.ToString(), v.ToString())]
return material_info
print(getMaterialInfo(DB))
print(getNetInfo(layout))
print(getComponentInfo(layout))
print(getStackupInfo(layout))
AEDT(ANSYS Electronics DeskTop)包含了HFSS, Designer, Q3D, Maxwell, Icepak, Simplorer, Mechanical等模擬軟體。本網誌分享如何利用Python編程,配合AEDT API(Application Programming Interface, 應用程式介面)來開發AEDT外掛工具。並介紹各類自動化模擬設定及模擬資料分析技巧。 版主:林鳴志(Lin, Ming Chih)
2020年9月26日 星期六
如何在PyCharm當中用EDB程式輸出net, component, stackup, material
2020年9月24日 星期四
如何在3D Layout當中讀取bondwire定義類別
有些版圖資料在AEDT當中並沒有函數可以讀取,比方說是bondwire的profile種類。這時候就必須透過edb來讀取。下面代碼可以讀取封裝設計專案當中的APD, Jedec4及Jedec5的profile。
import Ansys.Ansoft.Edb as edb
oProject = oDesktop.GetActiveProject()
handle = oProject.GetEDBHandle()
DB = edb.Database.Attach(int(handle))
edb.Database.Create(DB.GetDirectory())
for i in DB.APDBondwireDefs:
AddWarningMessage(str(i.GetName()))
for i in DB.Jedec4BondwireDefs:
AddWarningMessage(str(i.GetName()))
for i in DB.Jedec5BondwireDefs:
AddWarningMessage(str(i.GetName()))
(圖一) 輸出bondwire類別 |
如何在PyCharm環境當中在不同版本AEDT測試Script?
PyCharm在最受歡迎的Python IDE排名當中一直都是名列前茅,PyCharm的Community版本更是提供免費使用。除了開發CPython程式,我們也可以在PyCharm開發AEDT的指令稿(Script)。在下載安裝PyCharm完成之後,開啟專案時,指定Existinf Interpretor到AnsysEM底下的ipy64.exe,如圖一所示:
圖一:設定ipy64.exe |
底下是PyCharm的編程環境,底下的程式碼會在AEDT 2019R3當中建立新的Project並回傳Project名稱。按下右上角綠色執行鍵即可在PyCharm底下的Terminal看到結果:
如果要測試該代碼是否可以在AEDT 2020R2上正常運作,修改程式碼如下:
圖二:在AEDT 2020R2執行Script |
sys.path.append('C:/Program Files/AnsysEM/AnsysEM20.2/Win64/')
sys.path.append('C:/Program Files/AnsysEM/AnsysEM20.2/Win64/PythonFiles/DesktopPlugin/')
import ScriptEnv
ScriptEnv.Initialize('Ansoft.ElectronicsDesktop.2020.2')
x=oDesktop.NewProject()
print(x.GetName())
2020年9月22日 星期二
如何在Ironpython當中連結Anaconda Python做numpy運算?
scriptA.py是在AEDT執行的IronPython程式。首先ScriptA將AEDT模擬資料輸出到data.csv當中(這裡用0,1,2,...13做示範)。接著用命令列呼叫Anaconda當中的Python執行ScriptB。ScriptB讀出data.csv資料轉為numpy格式並完成加總,接著將加總資料寫入result.csv。最後ScriptA讀取result.csv並輸出到AEDT的訊息視窗當中。
# scriptA
import os, sys
sys.path.append(os.path.dirname(__file__))
os.chdir(os.path.dirname(__file__))
with open('data.csv', 'w') as f:
for i in range(14):
f.writelines(str(i) + '\n')
os.system('call C:\ProgramData\Anaconda3\Scripts\activate.bat & C:\ProgramData\Anaconda3\python.exe .\scriptB.py')
with open('result.csv') as f:
result = f.readline()
AddWarningMessage(result)
# scriptB
import numpy as np
with open('data.csv') as f:
x = np.array([float(i) for i in f.readlines()])
with open('result.csv', 'w') as f:
f.write(str(np.sum(x)))