Download this example

Download this example as a Jupyter Notebook or as a Python script.


Geometry import from maps#

This example shows how to use PyAEDT to create an HFSS SBR+ project from OpenStreetMap.

Keywords: HFSS, SBR+, city.

Perform imports and define constants#

Perform required imports and set up the local path to the PyAEDT directory path.

[1]:
import os
import tempfile
import time
[2]:
import ansys.aedt.core

Define constants.

[3]:
AEDT_VERSION = "2024.2"
NG_MODE = False  # Open AEDT UI when it is launched.

Create temporary directory#

Create a temporary directory where downloaded data or dumped data can be stored. If you’d like to retrieve the project data for subsequent use, the temporary folder name is given by temp_folder.name.

[4]:
temp_folder = tempfile.TemporaryDirectory(suffix=".ansys")

Launch HFSS and open project#

Launch HFSS and open the project.

[5]:
project_name = os.path.join(temp_folder.name, "city.aedt")
app = ansys.aedt.core.Hfss(
    project=project_name,
    design="Ansys",
    solution_type="SBR+",
    version=AEDT_VERSION,
    new_desktop=True,
    non_graphical=NG_MODE,
)
PyAEDT INFO: Python version 3.10.11 (tags/v3.10.11:7d4cc5a, Apr  5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)].
PyAEDT INFO: PyAEDT version 0.15.dev0.
PyAEDT INFO: Initializing new Desktop session.
PyAEDT INFO: Log on console is enabled.
PyAEDT INFO: Log on file C:\Users\ansys\AppData\Local\Temp\pyaedt_ansys_27a77382-c097-48da-869e-78535ac4aa37.log is enabled.
PyAEDT INFO: Log on AEDT is enabled.
PyAEDT INFO: Debug logger is disabled. PyAEDT methods will not be logged.
PyAEDT INFO: Launching PyAEDT with gRPC plugin.
PyAEDT INFO: New AEDT session is starting on gRPC port 57785.
PyAEDT WARNING: Electronics Desktop license not found on the default license server.
PyAEDT INFO: Electronics Desktop started on gRPC port: 57785 after 1.5452344417572021 seconds.
PyAEDT INFO: AEDT installation Path C:\Program Files\AnsysEM\v242\Win64
PyAEDT INFO: Ansoft.ElectronicsDesktop.2024.2 version started with process ID 13468.
PyAEDT INFO: Project city has been created.
PyAEDT INFO: Added design 'Ansys' of type HFSS.
PyAEDT INFO: Aedt Objects correctly read

Define location to import#

Define the latitude and longitude of the location to import.

[6]:
ansys_home = [40.273726, -80.168269]

Generate map and import#

Assign boundaries.

[7]:
app.modeler.import_from_openstreet_map(
    ansys_home,
    terrain_radius=250,
    road_step=3,
    plot_before_importing=False,
    import_in_aedt=True,
)
PyAEDT INFO: Modeler class has been initialized! Elapsed time: 0m 1sec
PyAEDT INFO: Generating Terrain
PyAEDT INFO: Terrain Points...
Percent Complete:........................................ 0%
Percent Complete:####.................................... 10%
Percent Complete:########................................ 20%
Percent Complete:############............................ 30%
Percent Complete:################........................ 40%
Percent Complete:####################.................... 50%
Percent Complete:########################................ 60%
Percent Complete:############################............ 70%
Percent Complete:################################........ 80%
Percent Complete:####################################.... 90%
PyAEDT INFO: 100% - Done
PyAEDT INFO: Processing Geometry
PyAEDT INFO: saving STL as C:\Users\ansys\AppData\Local\Temp\tmpk_n1_ouv.ansys\city.pyaedt\Ansys/terrain.stl
PyAEDT INFO: Generating Building Geometry
PyAEDT INFO:
Generating Buildings
Percent Complete:######################################## 100.0%
PyAEDT INFO: Generating Road Geometry
C:\actions-runner\_work\pyaedt-examples\pyaedt-examples\.venv\lib\site-packages\pyvista\core\filters\poly_data.py:2997: PyVistaFutureWarning: The default value of the ``capping`` keyword argument will change in a future version to ``True`` to match the behavior of VTK. We recommend passing the keyword explicitly to prevent future surprises.
  warnings.warn(
C:\actions-runner\_work\pyaedt-examples\pyaedt-examples\.venv\lib\site-packages\osmnx\graph.py:106: FutureWarning: The clean_periphery argument has been deprecated and will be removed in the v2.0.0 release. Future behavior will be as though clean_periphery=True.
  G = graph_from_polygon(
Percent Complete:########................................ 20.0%
Percent Complete:############............................ 30.0%
Percent Complete:####################.................... 50.0%
Percent Complete:############################............ 70.0%
Percent Complete:################################........ 80.0%
Percent Complete:######################################## 100.0%
PyAEDT INFO: Done...
PyAEDT INFO: Step file C:\Users\ansys\AppData\Local\Temp\tmpk_n1_ouv.ansys\city.pyaedt\Ansys/terrain.stl imported
PyAEDT INFO: Step file C:\Users\ansys\AppData\Local\Temp\tmpk_n1_ouv.ansys\city.pyaedt\Ansys\buildings.stl imported
PyAEDT ERROR: **************************************************************
PyAEDT ERROR:   File "C:\Users\ansys\AppData\Local\Programs\Python\Python310\Lib\runpy.py", line 196, in _run_module_as_main
PyAEDT ERROR:     return _run_code(code, main_globals, None,
PyAEDT ERROR:   File "C:\Users\ansys\AppData\Local\Programs\Python\Python310\Lib\runpy.py", line 86, in _run_code
PyAEDT ERROR:     exec(code, run_globals)
PyAEDT ERROR:   File "C:\actions-runner\_work\pyaedt-examples\pyaedt-examples\.venv\lib\site-packages\ipykernel_launcher.py", line 18, in <module>
PyAEDT ERROR:     app.launch_new_instance()
PyAEDT ERROR:   File "C:\actions-runner\_work\pyaedt-examples\pyaedt-examples\.venv\lib\site-packages\traitlets\config\application.py", line 1075, in launch_instance
PyAEDT ERROR:     app.start()
PyAEDT ERROR:   File "C:\actions-runner\_work\pyaedt-examples\pyaedt-examples\.venv\lib\site-packages\ipykernel\kernelapp.py", line 739, in start
PyAEDT ERROR:     self.io_loop.start()
PyAEDT ERROR:   File "C:\actions-runner\_work\pyaedt-examples\pyaedt-examples\.venv\lib\site-packages\tornado\platform\asyncio.py", line 205, in start
PyAEDT ERROR:     self.asyncio_loop.run_forever()
PyAEDT ERROR:   File "C:\Users\ansys\AppData\Local\Programs\Python\Python310\Lib\asyncio\base_events.py", line 603, in run_forever
PyAEDT ERROR:     self._run_once()
PyAEDT ERROR:   File "C:\Users\ansys\AppData\Local\Programs\Python\Python310\Lib\asyncio\base_events.py", line 1909, in _run_once
PyAEDT ERROR:     handle._run()
PyAEDT ERROR:   File "C:\Users\ansys\AppData\Local\Programs\Python\Python310\Lib\asyncio\events.py", line 80, in _run
PyAEDT ERROR:     self._context.run(self._callback, *self._args)
PyAEDT ERROR:   File "C:\actions-runner\_work\pyaedt-examples\pyaedt-examples\.venv\lib\site-packages\ipykernel\kernelbase.py", line 545, in dispatch_queue
PyAEDT ERROR:     await self.process_one()
PyAEDT ERROR:   File "C:\actions-runner\_work\pyaedt-examples\pyaedt-examples\.venv\lib\site-packages\ipykernel\kernelbase.py", line 534, in process_one
PyAEDT ERROR:     await dispatch(*args)
PyAEDT ERROR:   File "C:\actions-runner\_work\pyaedt-examples\pyaedt-examples\.venv\lib\site-packages\ipykernel\kernelbase.py", line 437, in dispatch_shell
PyAEDT ERROR:     await result
PyAEDT ERROR:   File "C:\actions-runner\_work\pyaedt-examples\pyaedt-examples\.venv\lib\site-packages\ipykernel\ipkernel.py", line 362, in execute_request
PyAEDT ERROR:     await super().execute_request(stream, ident, parent)
PyAEDT ERROR:   File "C:\actions-runner\_work\pyaedt-examples\pyaedt-examples\.venv\lib\site-packages\ipykernel\kernelbase.py", line 778, in execute_request
PyAEDT ERROR:     reply_content = await reply_content
PyAEDT ERROR:   File "C:\actions-runner\_work\pyaedt-examples\pyaedt-examples\.venv\lib\site-packages\ipykernel\ipkernel.py", line 449, in do_execute
PyAEDT ERROR:     res = shell.run_cell(
PyAEDT ERROR:   File "C:\actions-runner\_work\pyaedt-examples\pyaedt-examples\.venv\lib\site-packages\ipykernel\zmqshell.py", line 549, in run_cell
PyAEDT ERROR:     return super().run_cell(*args, **kwargs)
PyAEDT ERROR:   File "C:\Users\ansys\AppData\Local\Temp\ipykernel_8632\2322522223.py", line 1, in <module>
PyAEDT ERROR:     app.modeler.import_from_openstreet_map(
PyAEDT ERROR:   File "C:\actions-runner\_work\pyaedt-examples\pyaedt-examples\.venv\lib\site-packages\ansys\aedt\core\modeler\modeler_3d.py", line 1336, in import_from_openstreet_map
PyAEDT ERROR:     self.import_3d_cad(parts_dict[part]["file_name"], create_lightweigth_part=create_lightweigth_part)
PyAEDT ERROR:   File "C:\actions-runner\_work\pyaedt-examples\pyaedt-examples\.venv\lib\site-packages\ansys\aedt\core\modeler\cad\primitives.py", line 4875, in import_3d_cad
PyAEDT ERROR:     self.oeditor.Import(vArg1)
PyAEDT ERROR: AEDT API Error on import_3d_cad
PyAEDT ERROR: Last Electronics Desktop Message - [error]  import native bodies: translation of c:/users/ansys/appdata/local/temp/tmpk_n1_ouv.ansys/city.pyaedt/ansys/roads.stl failed. (04:45:54 am  feb 18, 2025)
PyAEDT ERROR: Method arguments:
PyAEDT ERROR:     input_file = C:\Users\ansys\AppData\Local\Temp\tmpk_n1_ouv.ansys\city.pyaedt\Ansys\roads.stl
PyAEDT ERROR:     create_lightweigth_part = True
PyAEDT ERROR: **************************************************************
[7]:
{'name': 'default',
 'version': 1,
 'type': 'environment',
 'center_lat_lon': [40.273726, -80.168269],
 'radius': 250,
 'include_buildings': True,
 'include_roads': True,
 'parts': {'terrain': {'file_name': 'C:\\Users\\ansys\\AppData\\Local\\Temp\\tmpk_n1_ouv.ansys\\city.pyaedt\\Ansys/terrain.stl',
   'color': 'brown',
   'material': 'earth'},
  'buildings': {'file_name': 'C:\\Users\\ansys\\AppData\\Local\\Temp\\tmpk_n1_ouv.ansys\\city.pyaedt\\Ansys\\buildings.stl',
   'color': 'grey',
   'material': 'concrete'},
  'roads': {'file_name': 'C:\\Users\\ansys\\AppData\\Local\\Temp\\tmpk_n1_ouv.ansys\\city.pyaedt\\Ansys\\roads.stl',
   'color': 'black',
   'material': 'asphalt'}}}

Plot model#

Plot the model.

[8]:
plot_obj = app.plot(show=False, plot_air_objects=True)
plot_obj.background_color = [153, 203, 255]
plot_obj.zoom = 1.5
plot_obj.show_grid = False
plot_obj.show_axes = False
plot_obj.bounding_box = False
plot_obj.plot(os.path.join(temp_folder.name, "Source.jpg"))
PyAEDT INFO: Parsing C:/Users/ansys/AppData/Local/Temp/tmpk_n1_ouv.ansys/city.aedt.
PyAEDT INFO: File C:/Users/ansys/AppData/Local/Temp/tmpk_n1_ouv.ansys/city.aedt correctly loaded. Elapsed time: 0m 0sec
PyAEDT INFO: aedt file load time 0.01556086540222168
PyAEDT INFO: PostProcessor class has been initialized! Elapsed time: 0m 0sec
PyAEDT INFO: Post class has been initialized! Elapsed time: 0m 0sec
C:\actions-runner\_work\pyaedt-examples\pyaedt-examples\.venv\lib\site-packages\pyvista\jupyter\notebook.py:37: UserWarning: Failed to use notebook backend:

No module named 'trame'

Falling back to a static output.
  warnings.warn(
../../../../_images/examples_high_frequency_antenna_large_scenarios_city_15_2.png
[8]:
True

Release AEDT#

Release AEDT and close the example.

[9]:
app.save_project()
app.release_desktop()
# Wait 3 seconds to allow AEDT to shut down before cleaning the temporary directory.
time.sleep(3)
PyAEDT INFO: Project city Saved correctly
PyAEDT INFO: Desktop has been released and closed.

Clean up#

All project files are saved in the folder temp_folder.name. If you’ve run this example as a Jupyter notebook, you can retrieve those project files. The following cell removes all temporary files, including the project folder.

[10]:
temp_folder.cleanup()

Download this example

Download this example as a Jupyter Notebook or as a Python script.