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,没有是1
        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中运行脚本,Tools=》Run script=》选择刚刚保存的.py文件。

结果

在这里插入图片描述
在这里插入图片描述
这样就导入了10000个点到HFSS中。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值