地方門戶網(wǎng)站模板seo教程seo優(yōu)化
HFSS 3維曲線導(dǎo)入
- 簡介
- 環(huán)境
- 參考
- 代碼
- 使用
- 結(jié)果
簡介
如圖一所示,CST中可以通過導(dǎo)入和到出由任意點組成的曲線,但是HFSS中貌似不能導(dǎo)入(如圖二所示),如果我們要將matlab的產(chǎn)生的曲線的點的數(shù)據(jù)導(dǎo)入特變麻煩,特別是在點特別多的情況。這時可以可以使用腳本導(dǎo)入海量個點所組成的曲線。
環(huán)境
python 3.11.5
Ansys Electronics Desktop 2022 R1
vscode
參考
【1】MATLAB-HFSS-API入門教程-第1講參考了HFSS的腳本使用的基本的介紹
代碼
腳本代碼由【1】的靈感在HFSS錄制出的腳本基礎(chǔ)上修改得來。
# ----------------------------------------------
# Script Recorded by Ansys Electronics Desktop Version 2022.1.0
# 20:42:37 8? 30, 2023
# ----------------------------------------------
import ScriptEnv
ScriptEnv.Initialize("Ansoft.ElectronicsDesktop")
oDesktop.RestoreWindow()
oProject = oDesktop.SetActiveProject("Project2")
oDesign = oProject.SetActiveDesign("HFSSDesign1")
oEditor = oDesign.SetActiveEditor("3D Modeler")
list1=[ "NAME:Attributes","Name:=" , "Polyline1","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]
list2=["NAME:PolylinePoints"]
list3=[ "NAME:PolylineParameters","IsPolylineCovered:=" , True,"IsPolylineClosed:=" , False,]
list4= [ ["NAME:PolylineSegments",["NAME:PLSegment","SegmentType:=" , "Spline","StartIndex:=" , 0,"NoOfPoints:=" , 10000, #根據(jù)文件修改對應(yīng)的點數(shù)(也是文件行數(shù))"NoOfSegments:=" , "0"]],["NAME:PolylineXSection","XSectionType:=" , "None","XSectionOrient:=" , "Auto","XSectionWidth:=" , "0mm","XSectionTopWidth:=" , "0mm","XSectionHeight:=" , "0mm","XSectionNumSegments:=" , "0","XSectionBendType:=" , "Corner"]]filename = "D:\study\mass\HfssCurve\script\\formalreadfile.txt"
with open(filename, 'r') as f:lines = f.readlines()
# print(len(lines))linelen=len(lines)
#可以看到點的數(shù)
out=[]
filename = "D:\study\mass\HfssCurve\script\\formalreadfile.txt" #保存點位置的txt文件
with open(filename, 'r') as f:lines = f.readlines()for line in lines:front=line[:line.find(",")]#????????front=front+"mm"
# print(front)end=line[line.find(",")+2:-2]end=end+"mm"
# print(end)temp=["NAME:PLPoint"]temp.append("X:=")temp.append(str(front))temp.append("Y:=")temp.append(str(end))temp.append("Z:=")temp.append("0mm")#print(temp)out.append(temp)
sumout=list2+out
#print(sumout)
sumout=[sumout]+list4
#print(sumout)
list3=list3+sumout
print(list3)
oEditor.CreatePolyline(list3,list1)
使用
保存點數(shù)文件的格式為坐標由逗號隔開。
0.00000000000000000, 0.000000000000000000.08071476209794981, -0.000000001413411610.16144074007196085, -0.000000010629037210.24217793799410914, -0.000000033594460550.32292635792965929, -0.000000074249612680.40368599995593835, -0.000000134547690320.48445686218176465, -0.000000214473345750.56523894076671022, -0.000000312061274600.64603222994000231, -0.000000423417759520.72683672202022986, -0.000000542737325300.80765240743457811, -0.000000662323998310.88847927473834076, -0.000000772608984790.96931731063373827, -0.00000086217232820
將上述修改對應(yīng)的路徑和點數(shù)后保存為.py文件,注意保存格式為ascii(win11的記事本不行),或在vscode保存為windows1252格式,只有這樣才能正常使用。
在HFSS中運行腳本,Tools=》Run script=》選擇剛剛保存的.py文件。
結(jié)果
這樣就導(dǎo)入了10000個點到HFSS中。