{ "cells": [ { "cell_type": "markdown", "id": "15b14d26", "metadata": {}, "source": [ "# Import Materials\n", "This example shows how to import materials." ] }, { "cell_type": "markdown", "id": "a88a7a09", "metadata": {}, "source": [ "### Import the required packages" ] }, { "cell_type": "code", "execution_count": null, "id": "8ec30b18", "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": "73198c65", "metadata": {}, "source": [ "Download the example PCB data." ] }, { "cell_type": "code", "execution_count": null, "id": "21dd3d2f", "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": "bcaa2cd5", "metadata": {}, "source": [ "## Load example layout." ] }, { "cell_type": "code", "execution_count": null, "id": "140f1375", "metadata": {}, "outputs": [], "source": [ "edbapp = Edb(file_edb, edbversion=AEDT_VERSION)" ] }, { "cell_type": "markdown", "id": "53b9cde5", "metadata": {}, "source": [ "## Review materials from layout" ] }, { "cell_type": "markdown", "id": "e92dea46", "metadata": {}, "source": [ "Get materials from layout in a dictionary. Materials are exported together with stadckup." ] }, { "cell_type": "code", "execution_count": null, "id": "4f159253", "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": "480074e8", "metadata": {}, "outputs": [], "source": [ "df = pd.DataFrame(data=data_cfg[\"stackup\"][\"materials\"])\n", "display(df)" ] }, { "cell_type": "markdown", "id": "55d93d08", "metadata": {}, "source": [ "## Add a new material" ] }, { "cell_type": "code", "execution_count": null, "id": "7d1d9b6b", "metadata": {}, "outputs": [], "source": [ "data_cfg[\"stackup\"][\"materials\"].append(\n", " {\"name\": \"soldermask\", \"permittivity\": 3.3, \"dielectric_loss_tangent\": 0.02},\n", ")" ] }, { "cell_type": "markdown", "id": "b170bfc1", "metadata": {}, "source": [ "## Edit existing material properties" ] }, { "cell_type": "code", "execution_count": null, "id": "52720b07", "metadata": {}, "outputs": [], "source": [ "data_cfg[\"stackup\"][\"materials\"][1][\"name\"] = \"fr4_epoxy\"\n", "data_cfg[\"stackup\"][\"materials\"][1][\"dielectric_loss_tangent\"] = 0.015" ] }, { "cell_type": "markdown", "id": "b0e787d0", "metadata": {}, "source": [ "## Review modified materials" ] }, { "cell_type": "code", "execution_count": null, "id": "cefdb083", "metadata": {}, "outputs": [], "source": [ "df = pd.DataFrame(data=data_cfg[\"stackup\"][\"materials\"])\n", "display(df)" ] }, { "cell_type": "markdown", "id": "0453917b", "metadata": {}, "source": [ "## Write material definition into a json file" ] }, { "cell_type": "code", "execution_count": null, "id": "72473a34", "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": "7f46113e", "metadata": {}, "source": [ "## Load materials from json configuration file" ] }, { "cell_type": "code", "execution_count": null, "id": "ed7a3c8a", "metadata": {}, "outputs": [], "source": [ "edbapp.configuration.load(str(file_cfg), apply_file=True)" ] }, { "cell_type": "markdown", "id": "180479e6", "metadata": {}, "source": [ "## Review materials from layout" ] }, { "cell_type": "code", "execution_count": null, "id": "23bf917e", "metadata": {}, "outputs": [], "source": [ "edbapp.materials.materials" ] }, { "cell_type": "markdown", "id": "e8fcaabd", "metadata": {}, "source": [ "## Check modified material properties" ] }, { "cell_type": "code", "execution_count": null, "id": "215bce80", "metadata": {}, "outputs": [], "source": [ "edbapp.materials[\"fr4_epoxy\"].loss_tangent" ] }, { "cell_type": "markdown", "id": "a86742ae", "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": "25b5ebfb", "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 }