{ "cells": [ { "cell_type": "markdown", "id": "2124ebe9", "metadata": {}, "source": [ "# Import Stackup\n", "This example shows how to import stackup file." ] }, { "cell_type": "markdown", "id": "921a4d7b", "metadata": {}, "source": [ "## Import the required packages" ] }, { "cell_type": "code", "execution_count": null, "id": "97cf3dab", "metadata": {}, "outputs": [], "source": [ "import json\n", "from pathlib import Path\n", "import tempfile\n", "\n", "from IPython.display import display\n", "from ansys.aedt.core.downloads import download_file\n", "import pandas as pd\n", "\n", "from pyedb import Edb\n", "\n", "AEDT_VERSION = \"2024.2\"\n", "NG_MODE = False\n" ] }, { "cell_type": "markdown", "id": "4c2aa717", "metadata": {}, "source": [ "Download the example PCB data." ] }, { "cell_type": "code", "execution_count": null, "id": "d29ecc22", "metadata": {}, "outputs": [], "source": [ "temp_folder = tempfile.TemporaryDirectory(suffix=\".ansys\")\n", "file_edb = download_file(source=\"edb/ANSYS-HSD_V1.aedb\", destination=temp_folder.name)" ] }, { "cell_type": "markdown", "id": "8ac2b3f4", "metadata": {}, "source": [ "## Load example layout." ] }, { "cell_type": "code", "execution_count": null, "id": "805d3c65", "metadata": {}, "outputs": [], "source": [ "edbapp = Edb(file_edb, edbversion=AEDT_VERSION)" ] }, { "cell_type": "markdown", "id": "49899120", "metadata": {}, "source": [ "## Review original stackup definition" ] }, { "cell_type": "markdown", "id": "99a2af6f", "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": "be1b6bec", "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": "e0ec46fe", "metadata": {}, "outputs": [], "source": [ "df = pd.DataFrame(data=data_cfg[\"stackup\"][\"layers\"])\n", "display(df)" ] }, { "cell_type": "markdown", "id": "271a05d7", "metadata": {}, "source": [ "## Modify stackup" ] }, { "cell_type": "markdown", "id": "8e01f543", "metadata": {}, "source": [ "Modify top layer thickness" ] }, { "cell_type": "code", "execution_count": null, "id": "5ea12e2a", "metadata": {}, "outputs": [], "source": [ "data_cfg[\"stackup\"][\"layers\"][0][\"thickness\"] = 0.00005" ] }, { "cell_type": "markdown", "id": "e2007429", "metadata": {}, "source": [ "Add a solder mask layer" ] }, { "cell_type": "code", "execution_count": null, "id": "cf94b16d", "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": "6dbdc1bc", "metadata": {}, "source": [ "Review modified stackup" ] }, { "cell_type": "code", "execution_count": null, "id": "783a9aba", "metadata": {}, "outputs": [], "source": [ "df = pd.DataFrame(data=data_cfg[\"stackup\"][\"layers\"])\n", "display(df.head(3))" ] }, { "cell_type": "markdown", "id": "373ec742", "metadata": {}, "source": [ "Write stackup definition into a json file" ] }, { "cell_type": "code", "execution_count": null, "id": "b869b795", "metadata": { "lines_to_next_cell": 2 }, "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": "4179b4c8", "metadata": {}, "source": [ "## Load stackup from json configuration file" ] }, { "cell_type": "code", "execution_count": null, "id": "fded4fa5", "metadata": {}, "outputs": [], "source": [ "edbapp.configuration.load(file_cfg, apply_file=True)" ] }, { "cell_type": "markdown", "id": "1911b29c", "metadata": {}, "source": [ "Plot stackup" ] }, { "cell_type": "code", "execution_count": null, "id": "0331e6bd", "metadata": {}, "outputs": [], "source": [ "edbapp.stackup.plot()" ] }, { "cell_type": "markdown", "id": "0bdde3c0", "metadata": {}, "source": [ "Check top layer thickness" ] }, { "cell_type": "code", "execution_count": null, "id": "1d038bf4", "metadata": {}, "outputs": [], "source": [ "edbapp.stackup[\"1_Top\"].thickness" ] }, { "cell_type": "markdown", "id": "91864905", "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": "e4cbd5b5", "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 }