{ "cells": [ { "cell_type": "markdown", "id": "9e9ce0b7", "metadata": {}, "source": [ "# Geometry import from maps\n", "\n", "This example shows how to use PyAEDT to create an HFSS SBR+ project from\n", "OpenStreetMap.\n", "\n", "Keywords: **HFSS**, **SBR+**, **city**." ] }, { "cell_type": "markdown", "id": "ccffe567", "metadata": {}, "source": [ "## Perform imports and define constants\n", "\n", "Perform required imports and set up the local path to the PyAEDT\n", "directory path." ] }, { "cell_type": "code", "execution_count": null, "id": "e624ec8e", "metadata": {}, "outputs": [], "source": [ "import os\n", "import tempfile\n", "import time" ] }, { "cell_type": "code", "execution_count": null, "id": "e9e07031", "metadata": {}, "outputs": [], "source": [ "import ansys.aedt.core" ] }, { "cell_type": "markdown", "id": "f62f3946", "metadata": {}, "source": [ "Define constants." ] }, { "cell_type": "code", "execution_count": null, "id": "0826c853", "metadata": {}, "outputs": [], "source": [ "AEDT_VERSION = \"2024.2\"\n", "NG_MODE = False # Open AEDT UI when it is launched." ] }, { "cell_type": "markdown", "id": "a3a7a391", "metadata": {}, "source": [ "## Create temporary directory\n", "\n", "Create a temporary directory where downloaded data or\n", "dumped data can be stored.\n", "If you'd like to retrieve the project data for subsequent use,\n", "the temporary folder name is given by ``temp_folder.name``." ] }, { "cell_type": "code", "execution_count": null, "id": "4d8ecaa7", "metadata": {}, "outputs": [], "source": [ "temp_folder = tempfile.TemporaryDirectory(suffix=\".ansys\")" ] }, { "cell_type": "markdown", "id": "121e3c6d", "metadata": {}, "source": [ "## Launch HFSS and open project\n", "\n", "Launch HFSS and open the project." ] }, { "cell_type": "code", "execution_count": null, "id": "5384cb23", "metadata": {}, "outputs": [], "source": [ "project_name = os.path.join(temp_folder.name, \"city.aedt\")\n", "app = ansys.aedt.core.Hfss(\n", " project=project_name,\n", " design=\"Ansys\",\n", " solution_type=\"SBR+\",\n", " version=AEDT_VERSION,\n", " new_desktop=True,\n", " non_graphical=NG_MODE,\n", ")" ] }, { "cell_type": "markdown", "id": "ef630d0d", "metadata": {}, "source": [ "## Define location to import\n", "\n", "Define the latitude and longitude of the location to import." ] }, { "cell_type": "code", "execution_count": null, "id": "894119fa", "metadata": {}, "outputs": [], "source": [ "ansys_home = [40.273726, -80.168269]" ] }, { "cell_type": "markdown", "id": "0c712129", "metadata": {}, "source": [ "## Generate map and import\n", "\n", "Assign boundaries." ] }, { "cell_type": "code", "execution_count": null, "id": "f17d8b6a", "metadata": {}, "outputs": [], "source": [ "app.modeler.import_from_openstreet_map(\n", " ansys_home,\n", " terrain_radius=250,\n", " road_step=3,\n", " plot_before_importing=False,\n", " import_in_aedt=True,\n", ")" ] }, { "cell_type": "markdown", "id": "932463ef", "metadata": {}, "source": [ "## Plot model\n", "\n", "Plot the model." ] }, { "cell_type": "code", "execution_count": null, "id": "7f2283f1", "metadata": {}, "outputs": [], "source": [ "plot_obj = app.plot(show=False, plot_air_objects=True)\n", "plot_obj.background_color = [153, 203, 255]\n", "plot_obj.zoom = 1.5\n", "plot_obj.show_grid = False\n", "plot_obj.show_axes = False\n", "plot_obj.bounding_box = False\n", "plot_obj.plot(os.path.join(temp_folder.name, \"Source.jpg\"))" ] }, { "cell_type": "markdown", "id": "edec983f", "metadata": {}, "source": [ "## Release AEDT\n", "\n", "Release AEDT and close the example." ] }, { "cell_type": "code", "execution_count": null, "id": "908236d2", "metadata": {}, "outputs": [], "source": [ "app.save_project()\n", "app.release_desktop()\n", "# Wait 3 seconds to allow AEDT to shut down before cleaning the temporary directory.\n", "time.sleep(3)" ] }, { "cell_type": "markdown", "id": "a9cd7987", "metadata": {}, "source": [ "## Clean up\n", "\n", "All project files are saved in the folder ``temp_folder.name``. If you've run this example as a Jupyter notebook, you\n", "can retrieve those project files. The following cell removes all temporary files, including the project folder." ] }, { "cell_type": "code", "execution_count": null, "id": "d7fefe6a", "metadata": {}, "outputs": [], "source": [ "temp_folder.cleanup()" ] } ], "metadata": { "jupytext": { "cell_metadata_filter": "-all", "main_language": "python", "notebook_metadata_filter": "-all" } }, "nbformat": 4, "nbformat_minor": 5 }