本文主要是介绍HFSS 3维曲线导入,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
HFSS 3维曲线导入
- 简介
- 环境
- 参考
- 代码
- 使用
- 结果
简介
如图一所示,CST中可以通过导入和到出由任意点组成的曲线,但是HFSS中貌似不能导入(如图二所示),如果我们要将matlab的产生的曲线的点的数据导入特变麻烦,特别是在点特别多的情况。这时可以可以使用脚本导入海量个点所组成的曲线。
环境
python 3.11.5
Ansys Electronics Desktop 2022 R1
vscode
参考
【1】MATLAB-HFSS-API入门教程-第1讲参考了HFSS的脚本使用的基本的介绍
代码
脚本代码由【1】的灵感在HFSS录制出的脚本基础上修改得来。
# ----------------------------------------------
# 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, #根据文件修改对应的点数(也是文件行数)"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)
#可以看到点的数
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]#逗号后面有空格的话是2,没有是1end=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)
使用
保存点数文件的格式为坐标由逗号隔开。
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
将上述修改对应的路径和点数后保存为.py文件,注意保存格式为ascii(win11的记事本不行),或在vscode保存为windows1252格式,只有这样才能正常使用。
在HFSS中运行脚本,Tools=》Run script=》选择刚刚保存的.py文件。
结果
这样就导入了10000个点到HFSS中。
这篇关于HFSS 3维曲线导入的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!