HFSS的脚本录制功能是一个强大的工具,可以显著提高用户的工作效率。通过录制和重用脚本,用户可以快速完成重复性的任务,减少手动操作的时间和错误。然而,在使用脚本录制功能时,也需要注意脚本的适用性、修改和调试等方面的问题。
脚本录制功能允许用户将软件中的操作自动记录为脚本,这些脚本可以在后续需要时运行以重现之前的操作,从而提高工作效率。时常还可用matlab等工具调用脚本,实现定制数据的需求。后面解析脚本的代码,可以将代码模块化,方便用matlab设计,能更灵活的做设计和建模操作。
As shown below👇
录制脚本功能
在HFSS的菜单栏上,找到“Tools”选项,然后在下拉菜单中选择“Record Script To File”。
此时会弹出一个对话框,要求用户输入脚本文件名和选择脚本类型。通常,HFSS支持VBScript(.vbs)和IronPython(*.py)两种脚本格式。
输入脚本名称,选择脚本类型,并指定保存位置,然后点击“保存”开始录制。
代码解析
1、创建工程
Dim oAnsoftApp
Dim oDesktop
Dim oProject
Dim oDesign
Dim oEditor
Dim oModule
Set oAnsoftApp = CreateObject("Ansoft.ElectronicsDesktop")
Set oDesktop = oAnsoftApp.GetAppDesktop()
oDesktop.RestoreWindow
Set oProject = oDesktop.NewProject
2、插入hfss design
oProject.InsertDesign "HFSS", "HFSSDesign1", "HFSS Modal Network", ""
Set oDesign = oProject.SetActiveDesign("HFSSDesign1")
Set oEditor = oDesign.SetActiveEditor("3D Modeler")
3、创建模型、设置材料
Set oEditor = oDesign.SetActiveEditor("3D Modeler")
oEditor.CreateBox Array("NAME:BoxParameters", "XPosition:=", "-1mm", "YPosition:=", _
"0mm", "ZPosition:=", "0mm", "XSize:=", "2.1mm", "YSize:=", "1.9mm", "ZSize:=", _
"-0.3mm"), Array("NAME:Attributes", "Name:=", "Box1", "Flags:=", "", "Color:=", _
"(143 175 143)", "Transparency:=", 0, "PartCoordinateSystem:=", "Global", "UDMId:=", _
"", "MaterialValue:=", "" & Chr(34) & "vacuum" & Chr(34) & "", "SurfaceMaterialValue:=", _
"" & Chr(34) & "" & Chr(34) & "", "SolveInside:=", true, "ShellElement:=", _
false, "ShellElementThickness:=", "0mm", "IsMaterialEditable:=", true, "UseMaterialAppearance:=", _
false, "IsLightweight:=", false)
4、创建边界条件、激励等
Set oModule = oDesign.GetModule("BoundarySetup")
oModule.AssignPerfectE Array("NAME:PerfE1", "Objects:=", Array("Rectangle1"), "InfGroundPlane:=", _
false)
oModule.AssignLumpedPort Array("NAME:1", "Objects:=", Array("Port"), "DoDeembed:=", _
false, "RenormalizeAllTerminals:=", true, Array("NAME:Modes", Array("NAME:Mode1", "ModeNum:=", _
1, "UseIntLine:=", true, Array("NAME:IntLine", "Coordinate System:=", "Global", "Start:=", Array( _
"-4.67780619902325e-17mm", "0mm", "-1.6mm"), "End:=", Array( _
"7.34788079488412e-17mm", "-1.2mm", "-1.6mm")), "AlignmentGroup:=", 0, "CharImp:=", _
"Zpi", "RenormImp:=", "50ohm")), "ShowReporterFilter:=", false, "ReporterFilter:=", Array( _
true), "Impedance:=", "50ohm")
5、设置扫描
Set oModule = oDesign.GetModule("AnalysisSetup")
oModule.InsertSetup "HfssDriven", Array("NAME:Setup1", "SolveType:=", "Single", "Frequency:=", _
"2.4GHz", "MaxDeltaS:=", 0.02, "UseMatrixConv:=", false, "MaximumPasses:=", 6, "MinimumPasses:=", _
1, "MinimumConvergedPasses:=", 1, "PercentRefinement:=", 30, "IsEnabled:=", _
true, Array("NAME:MeshLink", "ImportMesh:=", false), "BasisOrder:=", 1, "DoLambdaRefine:=", _
true, "DoMaterialLambda:=", true, "SetLambdaTarget:=", false, "Target:=", _
0.3333, "UseMaxTetIncrease:=", false, "PortAccuracy:=", 2, "UseABCOnPort:=", _
false, "SetPortMinMaxTri:=", false, "UseDomains:=", false, "UseIterativeSolver:=", _
false, "EnhancedLowFreqAccuracy:=", false, "SaveRadFieldsOnly:=", false, "SaveAnyFields:=", _
true, "IESolverType:=", "Auto", "LambdaTargetForIESolver:=", 0.15, "UseDefaultLambdaTgtForIESolver:=", _
true, "IE Solver Accuracy:=", "Balanced", "InfiniteSphereSetup:=", "")
oModule.InsertFrequencySweep "Setup1", Array("NAME:Sweep", "IsEnabled:=", true, "RangeType:=", _
"LinearStep", "RangeStart:=", "1.5GHz", "RangeEnd:=", "3GHz", "RangeStep:=", _
"0.01GHz", "Type:=", "Fast", "SaveFields:=", true, "SaveRadFields:=", false, "GenerateFieldsForAllFreqs:=", _
false)
5、获取数据
Set oModule = oDesign.GetModule("ReportSetup")
oModule.CreateReport "S Parameter Plot 1", "Modal Solution Data", _
"Rectangular Plot", "Setup1 : Sweep", Array("Domain:=", "Sweep"), Array("Freq:=", Array( _
"All"), "Sub_W:=", Array("Nominal"), "Sub_L:=", Array("Nominal"), "Sub_h:=", Array( _
"Nominal"), "Patch_w:=", Array("Nominal"), "Patch_l:=", Array("Nominal"), "Feedx:=", Array( _
"Nominal"), "Feedy:=", Array("Nominal"), "Feedr:=", Array("Nominal"), "PortR:=", Array( _
"Nominal"), "c:=", Array("Nominal"), "f:=", Array("Nominal")), Array("X Component:=", _
"Freq", "Y Component:=", Array("dB(S(1,1))"))
ps:一些不完整的hfss脚本(持续添加)
链接: https://pan.baidu.com/s/1G3aZHdy3bPevo97erU7zVg?pwd=hfss
提取码: hfss