EDB simple example#
This example shows how to use the EDBCommon class to open an existing EDB project.
Perform required imports#
Perform the required imports.
[1]:
import os
import shutil
[2]:
from ansys.aedt.core import generate_unique_folder_name
[3]:
from ansys.tools.common.example_download import download_manager
from ansys.aedt.toolkits.common.backend.api import EDBCommon
Initialize temporary folder and project settings#
Initialize a temporary folder to copy the input file into and specify project settings.
[4]:
temp_folder = os.path.join(generate_unique_folder_name())
edb_path = os.path.join(temp_folder, "edb_example.aedb")
os.makedirs(edb_path, exist_ok=True)
local_project = download_manager.download_file("edb.def", "toolkits/common", edb_path)
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
File C:\actions-runner\_work\pyaedt-toolkits-common\pyaedt-toolkits-common\.venv\Lib\site-packages\ansys\tools\common\example_download.py:555, in DownloadManager._download_file_git_based(self, filename, directory, destination, force, timeout, max_retries)
554 else:
--> 555 raise FileNotFoundError(f"File not found in repository: {file_path_in_repo}")
556 except (subprocess.TimeoutExpired, Exception) as e:
FileNotFoundError: File not found in repository: toolkits/common/edb.def
The above exception was the direct cause of the following exception:
DownloadError Traceback (most recent call last)
File C:\actions-runner\_work\pyaedt-toolkits-common\pyaedt-toolkits-common\.venv\Lib\site-packages\ansys\tools\common\example_download.py:157, in DownloadManager.download_file(self, filename, directory, destination, force, timeout, max_retries)
156 try:
--> 157 local_path = self._download_file_git_based(
158 filename, directory, destination_path, force, timeout, max_retries
159 )
160 except Exception:
File C:\actions-runner\_work\pyaedt-toolkits-common\pyaedt-toolkits-common\.venv\Lib\site-packages\ansys\tools\common\example_download.py:561, in DownloadManager._download_file_git_based(self, filename, directory, destination, force, timeout, max_retries)
560 else:
--> 561 raise DownloadError(
562 f"Failed to download file '{file_path_in_repo}' after {max_retries} attempts: {e}"
563 ) from e
564 finally:
DownloadError: Failed to download file 'toolkits/common/edb.def' after 3 attempts: File not found in repository: toolkits/common/edb.def
During handling of the above exception, another exception occurred:
HTTPError Traceback (most recent call last)
File C:\actions-runner\_work\pyaedt-toolkits-common\pyaedt-toolkits-common\.venv\Lib\site-packages\ansys\tools\common\example_download.py:777, in DownloadManager._retrieve_data(self, url, filename, destination, directory, force, timeout, max_retries)
776 response = requests.get(url, timeout=timeout)
--> 777 response.raise_for_status()
779 local_path.parent.mkdir(parents=True, exist_ok=True)
File C:\actions-runner\_work\pyaedt-toolkits-common\pyaedt-toolkits-common\.venv\Lib\site-packages\requests\models.py:1167, in Response.raise_for_status(self)
1166 if http_error_msg:
-> 1167 raise HTTPError(http_error_msg, response=self)
HTTPError: 404 Client Error: Not Found for url: https://github.com/ansys/example-data/raw/main/toolkits/common/edb.def
The above exception was the direct cause of the following exception:
DownloadError Traceback (most recent call last)
Cell In[4], line 4
1 temp_folder = os.path.join(generate_unique_folder_name())
2 edb_path = os.path.join(temp_folder, "edb_example.aedb")
3 os.makedirs(edb_path, exist_ok=True)
----> 4 local_project = download_manager.download_file("edb.def", "toolkits/common", edb_path)
File C:\actions-runner\_work\pyaedt-toolkits-common\pyaedt-toolkits-common\.venv\Lib\site-packages\ansys\tools\common\example_download.py:161, in DownloadManager.download_file(self, filename, directory, destination, force, timeout, max_retries)
157 local_path = self._download_file_git_based(
158 filename, directory, destination_path, force, timeout, max_retries
159 )
160 except Exception:
--> 161 local_path = self._download_file_http_based(
162 filename, directory, destination_path, force, timeout, max_retries
163 )
165 # Add path to downloaded files
166 self._add_file(local_path)
File C:\actions-runner\_work\pyaedt-toolkits-common\pyaedt-toolkits-common\.venv\Lib\site-packages\ansys\tools\common\example_download.py:613, in DownloadManager._download_file_http_based(self, filename, directory, destination, force, timeout, max_retries)
578 """Download a single file using HTTP.
579
580 Parameters
(...) 610 attempts.
611 """
612 url = self._get_filepath_on_default_server(filename, directory)
--> 613 local_path = self._retrieve_data(
614 url, filename, destination, directory=directory, force=force, timeout=timeout, max_retries=max_retries
615 )
616 return local_path
File C:\actions-runner\_work\pyaedt-toolkits-common\pyaedt-toolkits-common\.venv\Lib\site-packages\ansys\tools\common\example_download.py:790, in DownloadManager._retrieve_data(self, url, filename, destination, directory, force, timeout, max_retries)
787 time.sleep(wait_time)
788 else:
789 # Final attempt failed
--> 790 raise DownloadError(f"Failed to download file from {url} after {max_retries} attempts: {e}") from e
DownloadError: Failed to download file from https://github.com/ansys/example-data/raw/main/toolkits/common/edb.def after 3 attempts: 404 Client Error: Not Found for url: https://github.com/ansys/example-data/raw/main/toolkits/common/edb.def
Initialize toolkit#
Initialize the toolkit.
[5]:
toolkit = EDBCommon()
Initialize EDB project#
Open the EDB project.
[6]:
load_edb_msg = toolkit.load_edb(edb_path)
C:\actions-runner\_work\pyaedt-toolkits-common\pyaedt-toolkits-common\.venv\Lib\site-packages\pyedb\generic\design_types.py:375: UserWarning: You are using PyEDB with grpc, which is currently in beta. Some feature might be missing or not working as expected. Please report any issue you find to the PyEDB team.
warnings.warn(GRPC_BETA_WARNING, UserWarning)
C:\actions-runner\_work\pyaedt-toolkits-common\pyaedt-toolkits-common\.venv\Lib\site-packages\pyedb\grpc\edb.py:2592: SyntaxWarning: "\T" is an invalid escape sequence. Such sequences will not work in the future. Did you mean "\\T"? A raw string is also an option.
>>> edb_zones = edb.copy_zones(r"C:\Temp\test")
C:\actions-runner\_work\pyaedt-toolkits-common\pyaedt-toolkits-common\.venv\Lib\site-packages\pyedb\grpc\database\components.py:2110: SyntaxWarning: "\m" is an invalid escape sequence. Such sequences will not work in the future. Did you mean "\\m"? A raw string is also an option.
>>> edb_file = r"C:\my_edb_file.aedb"
PyEDB INFO: Logger is initialized in EDB.
PyEDB INFO: legacy v0.76.0
PyEDB INFO: Python version 3.14.5 (tags/v3.14.5:5607950, May 10 2026, 10:43:50) [MSC v.1944 64 bit (AMD64)]
PyEDB INFO: Using PyEDB with gRPC as Beta until ANSYS 2027R1 official release.
PyEDB INFO: Logger is initialized in EDB.
PyEDB INFO: legacy v0.76.0
PyEDB INFO: Python version 3.14.5 (tags/v3.14.5:5607950, May 10 2026, 10:43:50) [MSC v.1944 64 bit (AMD64)]
PyEDB INFO: Grpc session started
PyEDB INFO: Grpc session started: pid=4592
PyEDB INFO: RPC session acquired (open databases: 1)
PyEDB INFO: Refreshing the Components dictionary.
PyEDB INFO: EDB C:\Users\ansys\AppData\Local\Temp\pyaedt_prj_1YZ\edb_example.aedb created correctly.
PyEDB INFO: EDB initialized.
Get toolkit properties#
Get toolkit properties, which contain the project information.
[7]:
new_properties = toolkit.get_properties()
edb_project = new_properties["active_project"]
Save project#
Copy the current project in a new file.
[8]:
directory, old_file_name = os.path.split(edb_project)
new_path = os.path.join(directory, "new_edb.aedb")
toolkit.save_edb(new_path)
INFO - Project C:\Users\ansys\AppData\Local\Temp\pyaedt_prj_1YZ\new_edb.aedb saved
[8]:
True
Get cell names#
Get cell names using PyEDB.
[9]:
toolkit.logger.info("Play with EDB")
cell_names = toolkit.edb.cell_names
toolkit.edb.nets.plot()
INFO - Play with EDB
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
Cell In[9], line 3
1 toolkit.logger.info("Play with EDB")
2 cell_names = toolkit.edb.cell_names
----> 3 toolkit.edb.nets.plot()
File C:\actions-runner\_work\pyaedt-toolkits-common\pyaedt-toolkits-common\.venv\Lib\site-packages\pyedb\common\nets.py:168, in CommonNets.plot(self, nets, layers, color_by_net, show_legend, save_plot, outline, size, plot_components, top_view, show, annotate_component_names, plot_vias, title, **kwargs)
166 plot_line(poly, add_points=False, color=(0.7, 0, 0), linewidth=4)
167 layer_colors = {i: k.color for i, k in self._pedb.stackup.layers.items()}
--> 168 top_layer = list(self._pedb.stackup.signal_layers.keys())[0]
169 bottom_layer = list(self._pedb.stackup.signal_layers.keys())[-1]
170 lines = []
IndexError: list index out of range
Save and release EDB#
Save and release EDB.
[10]:
toolkit.close_edb()
PyEDB INFO: RPC session released (open databases: 0)
C:\actions-runner\_work\pyaedt-toolkits-common\pyaedt-toolkits-common\src\ansys\aedt\toolkits\common\backend\api.py:1072: FutureWarning: Call to deprecated function close_edb. Use close() instead.
self.edb.close_edb()
INFO - EDB is closed.
[10]:
True
Remove temporary folder#
Remove the temporary folder.
[11]:
shutil.rmtree(temp_folder, ignore_errors=True)