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:442, in DownloadManager._download_file_git_based(self, filename, directory, destination, force, timeout, max_retries)
    441     else:
--> 442         raise FileNotFoundError(f"File not found in repository: {file_path_in_repo}")
    443 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:

RuntimeError                              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:124, in DownloadManager.download_file(self, filename, directory, destination, force, timeout, max_retries)
    123 try:
--> 124     local_path = self._download_file_git_based(
    125         filename, directory, destination_path, force, timeout, max_retries
    126     )
    127 except Exception:

File C:\actions-runner\_work\pyaedt-toolkits-common\pyaedt-toolkits-common\.venv\Lib\site-packages\ansys\tools\common\example_download.py:448, in DownloadManager._download_file_git_based(self, filename, directory, destination, force, timeout, max_retries)
    447     else:
--> 448         raise RuntimeError(f"Git operation failed after {max_retries} attempts: {e}") from e
    449 finally:

RuntimeError: Git operation failed 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:624, in DownloadManager._retrieve_data(self, url, filename, destination, force, timeout, max_retries)
    623 response = requests.get(url, timeout=timeout)
--> 624 response.raise_for_status()
    626 Path(local_path).write_bytes(response.content)

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:

RuntimeError                              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:128, in DownloadManager.download_file(self, filename, directory, destination, force, timeout, max_retries)
    124     local_path = self._download_file_git_based(
    125         filename, directory, destination_path, force, timeout, max_retries
    126     )
    127 except Exception:
--> 128     local_path = self._download_file_http_based(
    129         filename, directory, destination_path, force, timeout, max_retries
    130     )
    132 # Add path to downloaded files
    133 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:481, in DownloadManager._download_file_http_based(self, filename, directory, destination, force, timeout, max_retries)
    463 """Download a single file using HTTP.
    464
    465 Parameters
   (...)    478     Maximum number of retry attempts for failed downloads.
    479 """
    480 url = self._get_filepath_on_default_server(filename, directory)
--> 481 local_path = self._retrieve_data(
    482     url, filename, destination, force=force, timeout=timeout, max_retries=max_retries
    483 )
    484 return local_path

File C:\actions-runner\_work\pyaedt-toolkits-common\pyaedt-toolkits-common\.venv\Lib\site-packages\ansys\tools\common\example_download.py:636, in DownloadManager._retrieve_data(self, url, filename, destination, force, timeout, max_retries)
    633     time.sleep(wait_time)
    634 else:
    635     # Final attempt failed
--> 636     raise RuntimeError(f"Failed to download file from {url} after {max_retries} attempts: {e}") from e

RuntimeError: 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.80.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)]
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=10800
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_M3O\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_M3O\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\.venv\Lib\site-packages\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)