HFSS 3维曲线导入

HFSS 3维曲线导入

  • 简介
  • 环境
  • 参考
  • 代码
  • 使用
  • 结果

简介

如图一所示,CST中可以通过导入和到出由任意点组成的曲线,但是HFSS中貌似不能导入(如图二所示),如果我们要将matlab的产生的曲线的点的数据导入特变麻烦,特别是在点特别多的情况。这时可以可以使用脚本导入海量个点所组成的曲线。

HFSS 3维曲线导入_第1张图片
HFSS 3维曲线导入_第2张图片

环境

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]
        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)

使用

保存点数文件的格式为坐标由逗号隔开。

 0.00000000000000000,  0.00000000000000000
 0.08071476209794981, -0.00000000141341161
 0.16144074007196085, -0.00000001062903721
 0.24217793799410914, -0.00000003359446055
 0.32292635792965929, -0.00000007424961268
 0.40368599995593835, -0.00000013454769032
 0.48445686218176465, -0.00000021447334575
 0.56523894076671022, -0.00000031206127460
 0.64603222994000231, -0.00000042341775952
 0.72683672202022986, -0.00000054273732530
 0.80765240743457811, -0.00000066232399831
 0.88847927473834076, -0.00000077260898479
 0.96931731063373827, -0.00000086217232820

将上述修改对应的路径和点数后保存为.py文件,注意保存格式为ascii(win11的记事本不行),或在vscode保存为windows1252格式,只有这样才能正常使用。
在这里插入图片描述

HFSS 3维曲线导入_第3张图片
在HFSS中运行脚本,Tools=》Run script=》选择刚刚保存的.py文件。

结果

HFSS 3维曲线导入_第4张图片
HFSS 3维曲线导入_第5张图片
这样就导入了10000个点到HFSS中。

你可能感兴趣的:(HFSS,HFSS)