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)
PyEDB INFO: gRPC mode enabled.
PyEDB INFO: Logger is initialized in EDB.
PyEDB INFO: legacy v0.87.0
PyEDB INFO: Python version 3.14.10 (tags/v3.14.10:b703b2c, Oct 25 2026, 17:36:52) [MSC v.1944 64 bit (AMD64)]
WARNING - The installed EDB_RPC_Server does not support shared-memory IPC. Falling back to standard gRPC communication. Update to the latest version of AEDT for improved performance.
PyEDB INFO: Grpc session started: pid=4328
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_1S0\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_1S0\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:172, 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, outline_width, plot_components_on_both_side, component_top_color, component_bottom_color, **kwargs)
    170     plot_line(poly, add_points=False, color=(0.7, 0, 0), linewidth=outline_width)
    171 layer_colors = {i: k.color for i, k in self._pedb.stackup.layers.items()}
--> 172 top_layer = list(self._pedb.stackup.signal_layers.keys())[0]
    173 bottom_layer = list(self._pedb.stackup.signal_layers.keys())[-1]
    174 lines = []

IndexError: list index out of range
../../_images/examples_edb_common_api_edb_16_2.png

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)