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.aedt.toolkits.common.utils import download_file
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]:
URL_BASE = "https://raw.githubusercontent.com/ansys/example-data/master/toolkits/common/"
EDB_PROJECT = "edb_edge_ports.aedb/edb.def"
URL = os.path.join(URL_BASE, EDB_PROJECT)

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 = os.path.join(edb_path, "edb.def")

download_file(URL, local_project)
[4]:
'C:\\Users\\ansys\\AppData\\Local\\Temp\\pyaedt_prj_J6P\\edb_example.aedb\\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: invalid escape sequence '\T'
  >>> 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:2111: SyntaxWarning: invalid escape sequence '\m'
  >>> edb_file = r"C:\my_edb_file.aedb"
PyEDB INFO: Logger is initialized in EDB.
PyEDB INFO: legacy v0.75.0
PyEDB INFO: Python version 3.12.10 (tags/v3.12.10:0cc8128, Apr  8 2025, 12:21:36) [MSC v.1943 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.75.0
PyEDB INFO: Python version 3.12.10 (tags/v3.12.10:0cc8128, Apr  8 2025, 12:21:36) [MSC v.1943 64 bit (AMD64)]
PyEDB INFO: Grpc session started
PyEDB INFO: Grpc session started: pid=8708
PyEDB INFO: RPC session acquired (open databases: 1)
PyEDB INFO: Database edb_example.aedb Opened in 2026.1
PyEDB INFO: Cell EMDesign1 Opened
PyEDB INFO: Refreshing the Components dictionary.
PyEDB INFO: Builder was initialized.
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_J6P\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
C:\actions-runner\_work\pyaedt-toolkits-common\pyaedt-toolkits-common\.venv\Lib\site-packages\pyedb\common\nets.py:343: FutureWarning: Accessing deprecated property primitives_by_layer. use layout.primitives_by_layer property instead.
  prims_by_layers_dict = {i: j for i, j in self._pedb.modeler.primitives_by_layer.items()}
../../_images/examples_edb_common_api_edb_16_1.png
PyEDB INFO: Plot Generation time 0.667
[9]:
(<Figure size 6000x3000 with 1 Axes>,
 <Axes: title={'center': 'Edb Top View EMDesign1'}>)

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:1071: 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)