{ "cells": [ { "cell_type": "markdown", "id": "69d9f0ae", "metadata": {}, "source": [ "# Import Stackup\n", "This example shows how to import stackup file." ] }, { "cell_type": "markdown", "id": "8f171dfb", "metadata": {}, "source": [ "## Perform imports and define constants\n", "\n", "Perform required imports." ] }, { "cell_type": "code", "execution_count": null, "id": "d110d157", "metadata": {}, "outputs": [], "source": [ "import json\n", "import toml\n", "from pathlib import Path\n", "import tempfile\n", "\n", "from IPython.display import display\n", "from ansys.aedt.core.examples.downloads import download_file\n", "import pandas as pd\n", "from pyedb import Edb" ] }, { "cell_type": "markdown", "id": "ccf7784e", "metadata": {}, "source": [ "Define constants." ] }, { "cell_type": "code", "execution_count": null, "id": "3d5c1d04", "metadata": {}, "outputs": [], "source": [ "AEDT_VERSION = \"2025.2\"\n", "NG_MODE = False" ] }, { "cell_type": "markdown", "id": "eeae4e01", "metadata": {}, "source": [ "Download the example PCB data." ] }, { "cell_type": "code", "execution_count": null, "id": "90d35d1a", "metadata": {}, "outputs": [], "source": [ "temp_folder = tempfile.TemporaryDirectory(suffix=\".ansys\")\n", "file_edb = download_file(source=\"edb/ANSYS-HSD_V1.aedb\", local_path=temp_folder.name)" ] }, { "cell_type": "markdown", "id": "210b42f6", "metadata": {}, "source": [ "## Load example layout." ] }, { "cell_type": "code", "execution_count": null, "id": "8b4966fe", "metadata": {}, "outputs": [], "source": [ "edbapp = Edb(file_edb, edbversion=AEDT_VERSION)" ] }, { "cell_type": "markdown", "id": "680187f3", "metadata": {}, "source": [ "## Review original stackup definition" ] }, { "cell_type": "markdown", "id": "a8d233c5", "metadata": {}, "source": [ "Get original stackup definition in a dictionary. Alternatively, stackup definition can be exported in a json file by\n", "edbapp.configuration.export()" ] }, { "cell_type": "code", "execution_count": null, "id": "09303f71", "metadata": { "lines_to_next_cell": 2 }, "outputs": [], "source": [ "data_cfg = edbapp.configuration.get_data_from_db(stackup=True)" ] }, { "cell_type": "code", "execution_count": null, "id": "44519e03", "metadata": {}, "outputs": [], "source": [ "df = pd.DataFrame(data=data_cfg[\"stackup\"][\"layers\"])\n", "display(df)" ] }, { "cell_type": "markdown", "id": "3676cfaf", "metadata": {}, "source": [ "## Modify stackup" ] }, { "cell_type": "markdown", "id": "cb7c4dd2", "metadata": {}, "source": [ "Modify top layer thickness" ] }, { "cell_type": "code", "execution_count": null, "id": "5de23aaa", "metadata": {}, "outputs": [], "source": [ "data_cfg[\"stackup\"][\"layers\"][0][\"thickness\"] = 0.00005" ] }, { "cell_type": "markdown", "id": "74abf1c9", "metadata": {}, "source": [ "Add a solder mask layer" ] }, { "cell_type": "code", "execution_count": null, "id": "e63dadf2", "metadata": {}, "outputs": [], "source": [ "data_cfg[\"stackup\"][\"layers\"].insert(\n", " 0, {\"name\": \"soler_mask\", \"type\": \"dielectric\", \"material\": \"Megtron4\", \"fill_material\": \"\", \"thickness\": 0.00002}\n", ")" ] }, { "cell_type": "markdown", "id": "3ec00404", "metadata": {}, "source": [ "Review modified stackup" ] }, { "cell_type": "code", "execution_count": null, "id": "9b3d050d", "metadata": {}, "outputs": [], "source": [ "df = pd.DataFrame(data=data_cfg[\"stackup\"][\"layers\"])\n", "display(df.head(3))" ] }, { "cell_type": "markdown", "id": "fbfe9aab", "metadata": {}, "source": [ "Write stackup definition into a json file" ] }, { "cell_type": "code", "execution_count": null, "id": "1a9117e1", "metadata": {}, "outputs": [], "source": [ "file_cfg = Path(temp_folder.name) / \"edb_configuration.json\"\n", "with open(file_cfg, \"w\") as f:\n", " json.dump(data_cfg, f, indent=4, ensure_ascii=False)" ] }, { "cell_type": "markdown", "id": "704f8ca8", "metadata": {}, "source": [ "Equivalent toml file looks like below " ] }, { "cell_type": "code", "execution_count": null, "id": "b6282e47", "metadata": {}, "outputs": [], "source": [ "toml_string = toml.dumps(data_cfg)\n", "print(toml_string)" ] }, { "cell_type": "markdown", "id": "73c94474", "metadata": {}, "source": [ "## Load stackup from json configuration file" ] }, { "cell_type": "code", "execution_count": null, "id": "8be433cc", "metadata": {}, "outputs": [], "source": [ "edbapp.configuration.load(file_cfg, apply_file=True)" ] }, { "cell_type": "markdown", "id": "1ab34dba", "metadata": {}, "source": [ "Plot stackup" ] }, { "cell_type": "code", "execution_count": null, "id": "7388c7ac", "metadata": {}, "outputs": [], "source": [ "edbapp.stackup.plot()" ] }, { "cell_type": "markdown", "id": "a056454a", "metadata": {}, "source": [ "Check top layer thickness" ] }, { "cell_type": "code", "execution_count": null, "id": "111dc9ea", "metadata": {}, "outputs": [], "source": [ "edbapp.stackup[\"1_Top\"].thickness" ] }, { "cell_type": "markdown", "id": "59d18f95", "metadata": {}, "source": [ "## Save and close Edb\n", "The temporary folder will be deleted once the execution of this script is finished. Replace **edbapp.save()** with\n", "**edbapp.save_as(\"C:/example.aedb\")** to keep the example project." ] }, { "cell_type": "code", "execution_count": null, "id": "e76e4601", "metadata": {}, "outputs": [], "source": [ "edbapp.save()\n", "edbapp.close()" ] } ], "metadata": { "jupytext": { "cell_metadata_filter": "-all", "main_language": "python", "notebook_metadata_filter": "-all" } }, "nbformat": 4, "nbformat_minor": 5 }