Copyright (C) 2024 - 2026 ANSYS, Inc. and/or its affiliates. SPDX-License-Identifier: Apache-2.0
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Create RCS setup from existing HFSS design#
This example demonstrates how to use the ToolkitBackend class. It initiates AEDT through PyAEDT, opens a HFSS design, creates a 3D Component and imports it in anew SBR+ design. Finally it creates the setup and proceeds analyze.
Perform required imports#
[1]:
import shutil
import sys
import tempfile
import time
[2]:
from ansys.aedt.toolkits.radar_explorer.backend.api import ToolkitBackend
from ansys.aedt.toolkits.radar_explorer.rcs_visualization import MonostaticRCSData
from ansys.aedt.toolkits.radar_explorer.rcs_visualization import MonostaticRCSPlotter
Set AEDT version#
Set AEDT version.
[3]:
aedt_version = "2026.1"
Set non-graphical mode#
Set non-graphical mode.
[4]:
non_graphical = False
Set number of cores#
[5]:
cores = 4
Create temporary directory#
[6]:
temp_dir = tempfile.TemporaryDirectory(suffix="_ansys")
Example project#
[7]:
original = r"example_models\ogive-IE.aedtz"
project_name = temp_dir.name / "ogive-IE.aedtz"
shutil.copy(original, project_name)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[7], line 2
1 original = r"example_models\ogive-IE.aedtz"
----> 2 project_name = temp_dir.name / "ogive-IE.aedtz"
3 shutil.copy(original, project_name)
TypeError: unsupported operand type(s) for /: 'str' and 'str'
Initialize toolkit#
Initialize the toolkit.
[8]:
toolkit_api = ToolkitBackend()
Set properties#
Set non-graphical mode.
[9]:
new_properties = {"non_graphical": non_graphical, "aedt_version": aedt_version}
flag1, msg1 = toolkit_api.set_properties(new_properties)
INFO - Updating internal properties.
Initialize AEDT#
Launch a new AEDT session in a thread.
[10]:
thread_msg = toolkit_api.launch_thread(toolkit_api.launch_aedt)
PyAEDT INFO: Python version 3.12.10 (tags/v3.12.10:0cc8128, Apr 8 2025, 12:21:36) [MSC v.1943 64 bit (AMD64)].
PyAEDT INFO: PyAEDT version 0.28.0.
PyAEDT INFO: Initializing new Desktop session.
Wait for the toolkit thread to be idle#
Wait for the toolkit thread to be idle and ready to accept a new task.
[11]:
idle = toolkit_api.wait_to_be_idle()
if not idle:
print("AEDT not initialized.")
sys.exit()
PyAEDT INFO: New AEDT session is starting on gRPC port 50084.
PyAEDT INFO: Starting new AEDT gRPC session on port 50084.
PyAEDT INFO: Launching AEDT server with gRPC transport mode: TransportMode.WNUA
PyAEDT INFO: Electronics Desktop started on gRPC port 50084 after 9.3 seconds.
PyAEDT INFO: AEDT installation Path C:\Program Files\ANSYS Inc\v261\AnsysEM
PyAEDT INFO: Connected to AEDT gRPC session on port 50084.
PyAEDT INFO: Non-graphical mode detected. Disabling Desktop logs.
PyAEDT INFO: Desktop has been released.
INFO - AEDT is released.
Open project#
Open the project.
[12]:
open_msg = toolkit_api.open_project(project_name)
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[12], line 1
----> 1 open_msg = toolkit_api.open_project(project_name)
NameError: name 'project_name' is not defined
Set setup properties#
[13]:
toolkit_api.properties.setup.setup_name = "Setup1"
toolkit_api.properties.setup.sweep_name = "LastAdaptive"
Get RCS data#
Direct export
[14]:
rcs_metadata = toolkit_api.export_rcs(excitation="IncPWave1", encode=False)
PyAEDT INFO: Python version 3.12.10 (tags/v3.12.10:0cc8128, Apr 8 2025, 12:21:36) [MSC v.1943 64 bit (AMD64)].
PyAEDT INFO: PyAEDT version 0.28.0.
PyAEDT INFO: Initializing Desktop session.
PyAEDT INFO: AEDT version 2026.1.
PyAEDT INFO: AEDT installation Path C:\Program Files\ANSYS Inc\v261\AnsysEM
PyAEDT INFO: Connected to AEDT gRPC session on port 50084.
PyAEDT INFO: Non-graphical mode detected. Disabling Desktop logs.
PyAEDT INFO: Python version 3.12.10 (tags/v3.12.10:0cc8128, Apr 8 2025, 12:21:36) [MSC v.1943 64 bit (AMD64)].
PyAEDT INFO: PyAEDT version 0.28.0.
PyAEDT INFO: Returning found Desktop session with PID 11332!
PyAEDT INFO: Project Project1 has been created.
PyAEDT INFO: Added design 'HFSS_FITEIM' of type HFSS.
PyAEDT INFO: AEDT objects correctly read
PyAEDT INFO: Project Project1 Saved correctly
PyAEDT INFO: Active Design set to HFSS_FITEIM
INFO - Updating internal properties.
INFO - Toolkit is connected to AEDT design.
INFO - Exporting RCS data for setup and sweep: Setup1 : LastAdaptive.
PyAEDT INFO: Parsing C:\Users\ansys\AppData\Local\Temp\pytest-of-ansys\pytest-4636\Project1.aedt.
PyAEDT INFO: File C:\Users\ansys\AppData\Local\Temp\pytest-of-ansys\pytest-4636\Project1.aedt correctly loaded. Elapsed time: 0m 0sec
PyAEDT INFO: aedt file load time 0.02497410774230957
PyAEDT INFO: PostProcessor class has been initialized! Elapsed time: 0m 0sec
PyAEDT INFO: PostProcessor class has been initialized! Elapsed time: 0m 0sec
PyAEDT INFO: Post class has been initialized! Elapsed time: 0m 0sec
PyAEDT ERROR: **************************************************************
PyAEDT ERROR: File "<frozen runpy>", line 198, in _run_module_as_main
PyAEDT ERROR: File "<frozen runpy>", line 88, in _run_code
PyAEDT ERROR: File "C:\actions-runner\_work\_tool\Python\3.12.10\x64\Lib\asyncio\base_events.py", line 645, in run_forever
PyAEDT ERROR: self._run_once()
PyAEDT ERROR: File "C:\actions-runner\_work\_tool\Python\3.12.10\x64\Lib\asyncio\base_events.py", line 1999, in _run_once
PyAEDT ERROR: handle._run()
PyAEDT ERROR: File "C:\actions-runner\_work\_tool\Python\3.12.10\x64\Lib\asyncio\events.py", line 88, in _run
PyAEDT ERROR: self._context.run(self._callback, *self._args)
PyAEDT ERROR: File "C:\Users\ansys\AppData\Local\Temp\ipykernel_9608\2380056415.py", line 1, in <module>
PyAEDT ERROR: rcs_metadata = toolkit_api.export_rcs(excitation="IncPWave1", encode=False)
PyAEDT ERROR: File "C:\actions-runner\_work\ansys-aedt-toolkits-radar-explorer\ansys-aedt-toolkits-radar-explorer\.venv\Lib\site-packages\ansys\aedt\toolkits\radar_explorer\backend\api.py", line 778, in export_rcs
PyAEDT ERROR: rcs_data = self.aedtapp.post.get_solution_data(
PyAEDT ERROR: File "C:\actions-runner\_work\ansys-aedt-toolkits-radar-explorer\ansys-aedt-toolkits-radar-explorer\.venv\Lib\site-packages\ansys\aedt\core\visualization\post\common.py", line 1817, in get_solution_data
PyAEDT ERROR: report = self._get_report_object(
PyAEDT ERROR: File "C:\actions-runner\_work\ansys-aedt-toolkits-radar-explorer\ansys-aedt-toolkits-radar-explorer\.venv\Lib\site-packages\ansys\aedt\core\visualization\post\common.py", line 1328, in _get_report_object
PyAEDT ERROR: raise KeyError(f"Setup {setup_name} not available in current design.")
PyAEDT ERROR: 'setup setup1 not available in current design.' on _get_report_object
PyAEDT ERROR: Method arguments:
PyAEDT ERROR: setup_sweep_name = Setup1 : LastAdaptive
PyAEDT ERROR: report_category = Monostatic RCS
PyAEDT ERROR: polyline_points = 1001
PyAEDT ERROR: **************************************************************
PyAEDT INFO: Desktop has been released and closed.
PyAEDT ERROR: **************************************************************
PyAEDT ERROR: File "<frozen runpy>", line 198, in _run_module_as_main
PyAEDT ERROR: File "<frozen runpy>", line 88, in _run_code
PyAEDT ERROR: File "C:\actions-runner\_work\_tool\Python\3.12.10\x64\Lib\asyncio\base_events.py", line 645, in run_forever
PyAEDT ERROR: self._run_once()
PyAEDT ERROR: File "C:\actions-runner\_work\_tool\Python\3.12.10\x64\Lib\asyncio\base_events.py", line 1999, in _run_once
PyAEDT ERROR: handle._run()
PyAEDT ERROR: File "C:\actions-runner\_work\_tool\Python\3.12.10\x64\Lib\asyncio\events.py", line 88, in _run
PyAEDT ERROR: self._context.run(self._callback, *self._args)
PyAEDT ERROR: File "C:\Users\ansys\AppData\Local\Temp\ipykernel_9608\2380056415.py", line 1, in <module>
PyAEDT ERROR: rcs_metadata = toolkit_api.export_rcs(excitation="IncPWave1", encode=False)
PyAEDT ERROR: File "C:\actions-runner\_work\ansys-aedt-toolkits-radar-explorer\ansys-aedt-toolkits-radar-explorer\.venv\Lib\site-packages\ansys\aedt\toolkits\radar_explorer\backend\api.py", line 778, in export_rcs
PyAEDT ERROR: rcs_data = self.aedtapp.post.get_solution_data(
PyAEDT ERROR: File "C:\actions-runner\_work\ansys-aedt-toolkits-radar-explorer\ansys-aedt-toolkits-radar-explorer\.venv\Lib\site-packages\ansys\aedt\core\visualization\post\common.py", line 1817, in get_solution_data
PyAEDT ERROR: report = self._get_report_object(
PyAEDT ERROR: ^^^^^^^^^^^^^^^^^^^^^^^^
PyAEDT ERROR: File "C:\actions-runner\_work\ansys-aedt-toolkits-radar-explorer\ansys-aedt-toolkits-radar-explorer\.venv\Lib\site-packages\ansys\aedt\core\visualization\post\common.py", line 1328, in _get_report_object
PyAEDT ERROR: raise KeyError(f"Setup {setup_name} not available in current design.")
PyAEDT ERROR: 'setup setup1 not available in current design.' on get_solution_data
PyAEDT ERROR: Method arguments:
PyAEDT ERROR: setup_sweep_name = Setup1 : LastAdaptive
PyAEDT ERROR: report_category = Monostatic RCS
PyAEDT ERROR: **************************************************************
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
Cell In[14], line 1
----> 1 rcs_metadata = toolkit_api.export_rcs(excitation="IncPWave1", encode=False)
File C:\actions-runner\_work\ansys-aedt-toolkits-radar-explorer\ansys-aedt-toolkits-radar-explorer\.venv\Lib\site-packages\ansys\aedt\toolkits\radar_explorer\backend\api.py:778, in ToolkitBackend.export_rcs(self, excitation, expression, encode)
775 else:
776 self.aedtapp.edit_sources(assignment={excitations[0]: "0", excitations[1]: "1"})
--> 778 rcs_data = self.aedtapp.post.get_solution_data(
779 expressions=expression,
780 variations=variations,
781 setup_sweep_name=setup_sweep_name,
782 report_category="Monostatic RCS",
783 )
784 frequencies = None
785 if rcs_data and getattr(rcs_data, "primary_sweep_values", None) is not None:
File C:\actions-runner\_work\ansys-aedt-toolkits-radar-explorer\ansys-aedt-toolkits-radar-explorer\.venv\Lib\site-packages\ansys\aedt\core\generic\general_methods.py:256, in _function_handler_wrapper.<locals>.wrapper(*args, **kwargs)
254 msg = msg.capitalize()
255 _exception(sys.exc_info(), user_function, args, kwargs, msg)
--> 256 return raise_exception_or_return_false(e)
File C:\actions-runner\_work\ansys-aedt-toolkits-radar-explorer\ansys-aedt-toolkits-radar-explorer\.venv\Lib\site-packages\ansys\aedt\core\generic\general_methods.py:218, in raise_exception_or_return_false(e)
215 for v in list(_desktop_sessions.values())[:]:
216 v.release_desktop(close_projects=v.close_on_exit, close_on_exit=v.close_on_exit)
--> 218 raise e
219 elif "__init__" in str(e): # pragma: no cover
220 return
File C:\actions-runner\_work\ansys-aedt-toolkits-radar-explorer\ansys-aedt-toolkits-radar-explorer\.venv\Lib\site-packages\ansys\aedt\core\generic\general_methods.py:231, in _function_handler_wrapper.<locals>.wrapper(*args, **kwargs)
229 try:
230 settings.time_tick = time.time()
--> 231 out = user_function(*args, **kwargs)
232 _log_method(user_function, args, kwargs)
233 return out
File C:\actions-runner\_work\ansys-aedt-toolkits-radar-explorer\ansys-aedt-toolkits-radar-explorer\.venv\Lib\site-packages\ansys\aedt\core\visualization\post\common.py:1817, in PostProcessorCommon.get_solution_data(self, expressions, setup_sweep_name, domain, variations, primary_sweep_variable, report_category, context, subdesign_id, polyline_points, math_formula)
1676 @pyaedt_function_handler()
1677 def get_solution_data(
1678 self,
(...) 1688 math_formula: str | None = None,
1689 ) -> "SolutionData":
1690 """Get a simulation result from a solved setup and cast it in a ``SolutionData`` object.
1691
1692 Data to be retrieved from Electronics Desktop are any simulation results available in that
(...) 1815 >>> m3d.desktop_class.release_desktop(False, False)
1816 """
-> 1817 report = self._get_report_object(
1818 expressions=expressions,
1819 setup_sweep_name=setup_sweep_name,
1820 domain=domain,
1821 variations=variations,
1822 primary_sweep_variable=primary_sweep_variable,
1823 secondary_sweep_variable=None,
1824 report_category=report_category,
1825 context=context,
1826 subdesign_id=subdesign_id,
1827 polyline_points=polyline_points,
1828 )
1829 if math_formula:
1830 expressions = [f"{math_formula}({i})" for i in report.expressions]
File C:\actions-runner\_work\ansys-aedt-toolkits-radar-explorer\ansys-aedt-toolkits-radar-explorer\.venv\Lib\site-packages\ansys\aedt\core\generic\general_methods.py:256, in _function_handler_wrapper.<locals>.wrapper(*args, **kwargs)
254 msg = msg.capitalize()
255 _exception(sys.exc_info(), user_function, args, kwargs, msg)
--> 256 return raise_exception_or_return_false(e)
File C:\actions-runner\_work\ansys-aedt-toolkits-radar-explorer\ansys-aedt-toolkits-radar-explorer\.venv\Lib\site-packages\ansys\aedt\core\generic\general_methods.py:218, in raise_exception_or_return_false(e)
215 for v in list(_desktop_sessions.values())[:]:
216 v.release_desktop(close_projects=v.close_on_exit, close_on_exit=v.close_on_exit)
--> 218 raise e
219 elif "__init__" in str(e): # pragma: no cover
220 return
File C:\actions-runner\_work\ansys-aedt-toolkits-radar-explorer\ansys-aedt-toolkits-radar-explorer\.venv\Lib\site-packages\ansys\aedt\core\generic\general_methods.py:231, in _function_handler_wrapper.<locals>.wrapper(*args, **kwargs)
229 try:
230 settings.time_tick = time.time()
--> 231 out = user_function(*args, **kwargs)
232 _log_method(user_function, args, kwargs)
233 return out
File C:\actions-runner\_work\ansys-aedt-toolkits-radar-explorer\ansys-aedt-toolkits-radar-explorer\.venv\Lib\site-packages\ansys\aedt\core\visualization\post\common.py:1328, in PostProcessorCommon._get_report_object(self, expressions, setup_sweep_name, domain, variations, primary_sweep_variable, secondary_sweep_variable, report_category, context, subdesign_id, polyline_points)
1323 setup_name = setup_sweep_name.split(":")[0].strip()
1324 if (
1325 self._app.design_type not in ["Circuit Netlist", "Twin Builder"]
1326 and setup_name not in self._app.setup_sweeps_names
1327 ):
-> 1328 raise KeyError(f"Setup {setup_name} not available in current design.")
1330 # Domain
1331 if not domain:
KeyError: 'Setup Setup1 not available in current design.'
Save and release AEDT#
[15]:
toolkit_api.release_aedt(True, True)
INFO - AEDT is released.
[15]:
True
Load RCS data#
[16]:
rcs_data = MonostaticRCSData(rcs_metadata)
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[16], line 1
----> 1 rcs_data = MonostaticRCSData(rcs_metadata)
NameError: name 'rcs_metadata' is not defined
Load RCS Plotter#
[17]:
rcs_data_plotter = MonostaticRCSPlotter(rcs_data)
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[17], line 1
----> 1 rcs_data_plotter = MonostaticRCSPlotter(rcs_data)
NameError: name 'rcs_data' is not defined
Select cut#
[18]:
primary_sweep = "IWavePhi"
secondary_sweep_value = rcs_data_plotter.rcs_data.incident_wave_theta
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[18], line 2
1 primary_sweep = "IWavePhi"
----> 2 secondary_sweep_value = rcs_data_plotter.rcs_data.incident_wave_theta
NameError: name 'rcs_data_plotter' is not defined
Plot RCS#
[19]:
plot = rcs_data_plotter.plot_rcs(primary_sweep=primary_sweep, secondary_sweep_value=secondary_sweep_value)
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[19], line 1
----> 1 plot = rcs_data_plotter.plot_rcs(primary_sweep=primary_sweep, secondary_sweep_value=secondary_sweep_value)
NameError: name 'rcs_data_plotter' is not defined
[20]:
plot_freq = rcs_data_plotter.plot_rcs(primary_sweep="Freq", secondary_sweep="IWavePhi")
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[20], line 1
----> 1 plot_freq = rcs_data_plotter.plot_rcs(primary_sweep="Freq", secondary_sweep="IWavePhi")
NameError: name 'rcs_data_plotter' is not defined
[21]:
# Wait 3 seconds to allow AEDT to shut down before cleaning the temporary directory.
time.sleep(3)
Clean temporary directory#
[22]:
temp_dir.cleanup()