{ "cells": [ { "cell_type": "markdown", "id": "05739114", "metadata": {}, "source": [ "# Import Stackup\n", "This example shows how to import stackup file." ] }, { "cell_type": "markdown", "id": "3cb5f4c7", "metadata": {}, "source": [ "## Perform imports and define constants\n", "\n", "Perform required imports." ] }, { "cell_type": "code", "execution_count": null, "id": "6f35ef7d", "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": "8cba4c1c", "metadata": {}, "source": [ "Define constants." ] }, { "cell_type": "code", "execution_count": null, "id": "b8fde511", "metadata": {}, "outputs": [], "source": [ "AEDT_VERSION = \"2025.1\"\n", "NG_MODE = False" ] }, { "cell_type": "markdown", "id": "d0c44759", "metadata": {}, "source": [ "Download the example PCB data." ] }, { "cell_type": "code", "execution_count": null, "id": "74d4163b", "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": "44d0d993", "metadata": {}, "source": [ "## Load example layout." ] }, { "cell_type": "code", "execution_count": null, "id": "faed714c", "metadata": {}, "outputs": [], "source": [ "edbapp = Edb(file_edb, edbversion=AEDT_VERSION)" ] }, { "cell_type": "markdown", "id": "9d4a80d1", "metadata": {}, "source": [ "## Review original stackup definition" ] }, { "cell_type": "markdown", "id": "3ec955a9", "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": "79e81c12", "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": "0fdd9b12", "metadata": {}, "outputs": [], "source": [ "df = pd.DataFrame(data=data_cfg[\"stackup\"][\"layers\"])\n", "display(df)" ] }, { "cell_type": "markdown", "id": "8936d292", "metadata": {}, "source": [ "## Modify stackup" ] }, { "cell_type": "markdown", "id": "20a01ffa", "metadata": {}, "source": [ "Modify top layer thickness" ] }, { "cell_type": "code", "execution_count": null, "id": "99048510", "metadata": {}, "outputs": [], "source": [ "data_cfg[\"stackup\"][\"layers\"][0][\"thickness\"] = 0.00005" ] }, { "cell_type": "markdown", "id": "ba077817", "metadata": {}, "source": [ "Add a solder mask layer" ] }, { "cell_type": "code", "execution_count": null, "id": "67d15126", "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": "cca0dbe0", "metadata": {}, "source": [ "Review modified stackup" ] }, { "cell_type": "code", "execution_count": null, "id": "b0798095", "metadata": {}, "outputs": [], "source": [ "df = pd.DataFrame(data=data_cfg[\"stackup\"][\"layers\"])\n", "display(df.head(3))" ] }, { "cell_type": "markdown", "id": "2a517c27", "metadata": {}, "source": [ "Write stackup definition into a json file" ] }, { "cell_type": "code", "execution_count": null, "id": "d582d55d", "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": "1a9c06bd", "metadata": {}, "source": [ "Equivalent toml file looks like below " ] }, { "cell_type": "code", "execution_count": null, "id": "a6393daf", "metadata": {}, "outputs": [], "source": [ "toml_string = toml.dumps(data_cfg)\n", "print(toml_string)" ] }, { "cell_type": "markdown", "id": "d3514d21", "metadata": {}, "source": [ "## Load stackup from json configuration file" ] }, { "cell_type": "code", "execution_count": null, "id": "f01b8afb", "metadata": {}, "outputs": [], "source": [ "edbapp.configuration.load(file_cfg, apply_file=True)" ] }, { "cell_type": "markdown", "id": "9965fbfa", "metadata": {}, "source": [ "Plot stackup" ] }, { "cell_type": "code", "execution_count": null, "id": "be722be9", "metadata": {}, "outputs": [], "source": [ "edbapp.stackup.plot()" ] }, { "cell_type": "markdown", "id": "83eb6762", "metadata": {}, "source": [ "Check top layer thickness" ] }, { "cell_type": "code", "execution_count": null, "id": "e9a15dee", "metadata": {}, "outputs": [], "source": [ "edbapp.stackup[\"1_Top\"].thickness" ] }, { "cell_type": "markdown", "id": "05f5f484", "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": "45985378", "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 }