在5G設計當中,使用者必須設定所有的port才能載入到HFSS當中觀察遠場,就算是沒用到的port也必須手動加入port名稱並設定0W, 0deg。本腳本可以讓使用者載入只有記錄部分ports的csv檔,沒有設定到的ports會自動設置為0W, 0deg。
import sys
import clr
from System.Windows.Forms import DialogResult, OpenFileDialog
clr.AddReference("System.Windows.Forms")
oDesktop.ClearMessages("", "", 2)
def setExcitation(csv_path):
oProject = oDesktop.GetActiveProject()
oDesign = oProject.GetActiveDesign()
oModule = oDesign.GetModule("BoundarySetup")
ports = [i.replace(':1', '') for i in oModule.GetExcitations()[::2]]
x = {name: ("0W", "0deg") for name in ports}
try:
with open(csv_path) as f:
text = f.readlines()
for i in text[1:]:
try:
source, magnitude, phase = i.split(',')
x[source.replace(':1', '')] = (magnitude, phase)
except:
pass
oModule = oDesign.GetModule("Solutions")
y = []
for name in x:
magnitude, phase = x[name]
y.append([
"Name:=" , name,
"Magnitude:=" , magnitude,
"Phase:=" , phase
])
oModule.EditSources(
[
[
"IncludePortPostProcessing:=", False,
"SpecifySystemPower:=" , False
],
] + y)
for name in x:
magnitude, phase = x[name]
AddInfoMessage("{}: {}, {}".format(name, magnitude, phase))
AddWarningMessage('Load "{}" successfully!'.format(csv_path))
except:
AddErrorMessage('Load "{}" failed!'.format(csv_path))
dialog = OpenFileDialog()
dialog.Title = "Load Excitation"
dialog.Filter = "csv files (*.csv)|*.csv"
if dialog.ShowDialog() == DialogResult.OK:
csv_path = dialog.FileName
setExcitation(csv_path)
else:
pass
沒有留言:
張貼留言