Example HFSS Scripts¶
Below are a variety of scripts that you can reference to do different things in
HFSS. These scripts are only compatible with HFSS 16, but each script is
completely self-contained. You can copy the script to a file and either run it
from the (command line) or run the script in HFSS by
clicking Tools → HFSS
in the GUI.
Creating a New Project¶
Create a new project; this is the base for many scripts from the command line. If you would rather open an existing script, see Opening an Existing Project.
"""Create a new project"""
import ScriptEnv
ScriptEnv.Initialize("Ansoft.ElectronicsDesktop")
oDesktop.RestoreWindow()
oProject = oDesktop.NewProject()
Opening an Existing Project¶
Often you’ll want to open an existing project (e.g., a template file) and make changes to it. The following script can open a project in HFSS.
Note
For this script to work for you, you will need to change line 5 to open a project that exists on your computer.
"""Open an existing project"""
import ScriptEnv
ScriptEnv.Initialize("Ansoft.ElectronicsDesktop")
oDesktop.RestoreWindow()
oDesktop.OpenProject("C:/Users/pier3595/Desktop/Project1.aedt")
Note
The rest of the code samples requires the file AntennaTemplate to be on your desktop in order tok run. You can download it and save it to your desktop, and the following examples will “just work.”
Changing a setup frequency and sweep frequency¶
Note
This script requires that you have AntennaTemplate.aedt on your desktop.
""""Change sweep solution frequency and a sweep frequency"""
# Locate the project file on your desktop
# These three lines are just plain Python, and have *nothing* to do with HFSS.
import os
project_file = os.path.join(os.path.expanduser('~'), 'Desktop')
project_file = os.path.join(project_file, 'AntennaTemplate.aedt')
import ScriptEnv
ScriptEnv.Initialize("Ansoft.ElectronicsDesktop")
oDesktop.RestoreWindow()
oDesktop.OpenProject(project_file)
oProject = oDesktop.SetActiveProject("AntennaTemplate")
oDesign = oProject.SetActiveDesign("HFSSDesign1")
oDesign.ChangeProperty(["NAME:AllTabs", ["NAME:HfssTab", ["NAME:PropServers", "AnalysisSetup:Setup8"],
["NAME:ChangedProps", [ "NAME:Solution Freq", "MustBeInt:=", False, "Value:=", "500MHz"]]]])
oDesign.ChangeProperty([ "NAME:AllTabs", ["NAME:HfssTab", ["NAME:PropServers", "AnalysisSetup:Setup8:Sweep1"],
["NAME:ChangedProps", [ "NAME:Start", "MustBeInt:=", False, "Value:=", "460MHz"]]]])
oDesign.ChangeProperty([ "NAME:AllTabs", [ "NAME:HfssTab", [ "NAME:PropServers", "AnalysisSetup:Setup8:Sweep1" ],
[ "NAME:ChangedProps", [ "NAME: Stop", "MustBeInt:=", False, "Value:=", "540MHz"]]]])
This script changes Setup8
‘s solution frequency to 500 MHz, and changes
Sweep1’s start frequency to 460 MHz and stop frequency to 540 MHz. But it also
does something a little more: it uses some normal Python functions to find
your desktop and open the file there. This makes the script much more
powerful; as long as you have the AntennaTemplate project on your
desktop, this script will run. Being able to use generic Python functions
makes scripting HFSS very powerful. This script uses the os module; you can
check out its docs if you want to.
Changing a Design Property¶
Note
This script requires that you have AntennaTemplate.aedt on your desktop.
This script will open the AntennaTemplate project and change the variable
ws
to the value 2mm
.
""""Change a design property."""
# Locate the project file on your desktop
# These three lines are just plain Python, and have *nothing* to do with HFSS.
import os
project_file = os.path.join(os.path.expanduser('~'), 'Desktop')
project_file = os.path.join(project_file, 'AntennaTemplate.aedt')
import ScriptEnv
ScriptEnv.Initialize("Ansoft.ElectronicsDesktop")
oDesktop.RestoreWindow()
oDesktop.OpenProject(project_file)
oProject = oDesktop.SetActiveProject("AntennaTemplate")
oDesign = oProject.SetActiveDesign("HFSSDesign1")
oDesign.ChangeProperty(["NAME:AllTabs", ["NAME:LocalVariableTab", ["NAME:PropServers", "LocalVariables"],
["NAME:ChangedProps", ["NAME:ws", "Value:=", "2mm"]]]])