假使我們之前已經用classical API開發了很多的自動化程式,能否在pyAEDT當中呼叫舊的程式碼,省去從頭開發的時間?答案是可以的,比方說,classical.py當中用舊的API開發的createBoxArray函數,我們可以在pyAEDT程式當中將其匯入,並使用該函數。底下範例使用non-graphical模式在不啟用GUI的狀況底下完成建模。
classical.py
def createBoxArray(m, n, spacing=1):
for i in range(m):
for j in range(n):
oEditor.CreateBox(
[
"NAME:BoxParameters",
"XPosition:=" , "{}mm".format(i*spacing),
"YPosition:=" , "{}mm".format(j*spacing),
"ZPosition:=" , "0mm",
"XSize:=" , "0.3mm",
"YSize:=" , "0.3mm",
"ZSize:=" , "0.4mm"
],
[
"NAME:Attributes",
"Name:=" , "Box1",
"Flags:=" , "",
"Color:=" , "(143 175 143)",
"Transparency:=" , 0,
"PartCoordinateSystem:=", "Global",
"UDMId:=" , "",
"MaterialValue:=" , "\"vacuum\"",
"SurfaceMaterialValue:=", "\"\"",
"SolveInside:=" , True,
"ShellElement:=" , False,
"ShellElementThickness:=", "0mm",
"IsMaterialEditable:=" , True,
"UseMaterialAppearance:=", False,
"IsLightweight:=" , False
])
new.py
from pyaedt import Hfss
hfss = Hfss(specified_version='2022.1', non_graphical=True)
import classical
classical.oEditor = hfss.modeler.oeditor
classical.createBoxArray(4, 8, 1)
hfss.plot()
沒有留言:
張貼留言