Copyright (C) 2024 - 2025 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 = "2025.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.23.0.
PyAEDT INFO: Initializing new Desktop session.
PyAEDT ERROR: **************************************************************
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 ERROR: File "C:\actions-runner\_work\_tool\Python\3.12.10\x64\Lib\threading.py", line 1032, in _bootstrap
PyAEDT ERROR: self._bootstrap_inner()
PyAEDT ERROR: File "C:\actions-runner\_work\_tool\Python\3.12.10\x64\Lib\threading.py", line 1075, in _bootstrap_inner
PyAEDT ERROR: self.run()
PyAEDT ERROR: File "C:\actions-runner\_work\_tool\Python\3.12.10\x64\Lib\threading.py", line 1012, in run
PyAEDT ERROR: self._target(*self._args, **self._kwargs)
PyAEDT ERROR: File "C:\actions-runner\_work\ansys-aedt-toolkits-radar-explorer\ansys-aedt-toolkits-radar-explorer\.venv\Lib\site-packages\ansys\aedt\toolkits\common\backend\thread_manager.py", line 55, in process_exe
PyAEDT ERROR: process(*args)
PyAEDT ERROR: File "C:\actions-runner\_work\ansys-aedt-toolkits-radar-explorer\ansys-aedt-toolkits-radar-explorer\.venv\Lib\site-packages\ansys\aedt\toolkits\common\backend\api.py", line 429, in launch_aedt
PyAEDT ERROR: self.desktop = ansys.aedt.core.Desktop(**desktop_args)
PyAEDT ERROR: File "C:\actions-runner\_work\ansys-aedt-toolkits-radar-explorer\ansys-aedt-toolkits-radar-explorer\.venv\Lib\site-packages\ansys\aedt\core\desktop.py", line 592, in __init__
PyAEDT ERROR: self.__check_version(version, student_version)
PyAEDT ERROR: File "C:\actions-runner\_work\ansys-aedt-toolkits-radar-explorer\ansys-aedt-toolkits-radar-explorer\.venv\Lib\site-packages\ansys\aedt\core\desktop.py", line 2397, in __check_version
PyAEDT ERROR: raise ValueError(
PyAEDT ERROR: Specified version 2025.1 is not installed on your system on __init__
PyAEDT ERROR: Method arguments:
PyAEDT ERROR: version = 2025.1
PyAEDT ERROR: new_desktop = True
PyAEDT ERROR: **************************************************************
Exception in thread Toolkit_Thread:
Traceback (most recent call last):
File "C:\actions-runner\_work\_tool\Python\3.12.10\x64\Lib\threading.py", line 1075, in _bootstrap_inner
self.run()
File "C:\actions-runner\_work\_tool\Python\3.12.10\x64\Lib\threading.py", line 1012, in run
self._target(*self._args, **self._kwargs)
File "C:\actions-runner\_work\ansys-aedt-toolkits-radar-explorer\ansys-aedt-toolkits-radar-explorer\.venv\Lib\site-packages\ansys\aedt\toolkits\common\backend\thread_manager.py", line 55, in process_exe
process(*args)
File "C:\actions-runner\_work\ansys-aedt-toolkits-radar-explorer\ansys-aedt-toolkits-radar-explorer\.venv\Lib\site-packages\ansys\aedt\toolkits\common\backend\api.py", line 429, in launch_aedt
self.desktop = ansys.aedt.core.Desktop(**desktop_args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: __init__() should return None, not 'bool'
ERROR - Toolkit has crashed and is not functional.
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)
ERROR - Process ID is not defined.
ERROR - Toolkit cannot connect to AEDT.
INFO - AEDT is released.
Save and release AEDT#
[15]:
toolkit_api.release_aedt(True, True)
ERROR - Process ID is not defined.
INFO - AEDT is released.
[15]:
True
Load RCS data#
[16]:
rcs_data = MonostaticRCSData(rcs_metadata)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[16], line 1
----> 1 rcs_data = MonostaticRCSData(rcs_metadata)
File C:\actions-runner\_work\ansys-aedt-toolkits-radar-explorer\ansys-aedt-toolkits-radar-explorer\.venv\Lib\site-packages\ansys\aedt\toolkits\radar_explorer\rcs_visualization.py:103, in MonostaticRCSData.__init__(self, input_file)
102 def __init__(self, input_file):
--> 103 input_file = Path(input_file)
104 # Public
105 self.output_dir = input_file.parent
File C:\actions-runner\_work\_tool\Python\3.12.10\x64\Lib\pathlib.py:1162, in Path.__init__(self, *args, **kwargs)
1159 msg = ("support for supplying keyword arguments to pathlib.PurePath "
1160 "is deprecated and scheduled for removal in Python {remove}")
1161 warnings._deprecated("pathlib.PurePath(**kwargs)", msg, remove=(3, 14))
-> 1162 super().__init__(*args)
File C:\actions-runner\_work\_tool\Python\3.12.10\x64\Lib\pathlib.py:373, in PurePath.__init__(self, *args)
371 path = arg
372 if not isinstance(path, str):
--> 373 raise TypeError(
374 "argument should be a str or an os.PathLike "
375 "object where __fspath__ returns a str, "
376 f"not {type(path).__name__!r}")
377 paths.append(path)
378 self._raw_paths = paths
TypeError: argument should be a str or an os.PathLike object where __fspath__ returns a str, not 'bool'
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()