Download this example

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


Environment import from open street map#

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

Keywords: HFSS, SBR+, city, OpenStreetMap

Prerequisites#

Perform imports#

[1]:
import os
import tempfile
import time

import ansys.aedt.core

Define constants#

Constants help ensure consistency and avoid repetition throughout the example.

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

Create temporary directory#

Create a temporary working directory. The name of the working folder is stored in temp_folder.name.

Note: The final cell in the notebook cleans up the temporary folder. If you want to retrieve the AEDT project and data, do so before executing the final cell in the notebook.

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

Launch HFSS and open project#

Launch HFSS and open the project. The solution type SBR+ instantiates a design type that supports the SBR+ solver.

[4]:
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.25.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_fba534e2-ab61-4b22-bf99-b39180e7be5a.log is enabled.
PyAEDT INFO: Log on AEDT is disabled.
PyAEDT INFO: Starting new AEDT gRPC session.
PyAEDT INFO: AEDT installation Path C:\Program Files\ANSYS Inc\v252\AnsysEM
PyAEDT INFO: Client application successfully started.
PyAEDT INFO: New AEDT gRPC session session started on port 50051.
PyAEDT INFO: 2025.2 version started with process ID 7348.
PyAEDT WARNING: Service Pack is not detected. PyAEDT is currently connecting in Insecure Mode.
PyAEDT WARNING: Please download and install latest Service Pack to use connect to AEDT in Secure Mode.
PyAEDT INFO: Debug logger is disabled. PyAEDT methods will not be logged.
PyAEDT INFO: Project city has been created.
PyAEDT INFO: Added design 'Ansys' of type HFSS.
PyAEDT INFO: Aedt Objects correctly read

Model Preparation#

Define the global location#

Define the latitude and longitude of the location to import from OpenStreetMap.

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

Generate map and import#

Import the model and define the domain size. The radius that defines the domain is specified in meters.

[6]:
app.modeler.import_from_openstreet_map(
    ansys_home,
    terrain_radius=250,
    road_step=3,
    plot_before_importing=True,
    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\tmpdpwnzar7.ansys\city.pyaedt\Ansys/terrain.stl
PyAEDT INFO: Generating Building Geometry
PyAEDT INFO:
Generating Buildings
Percent Complete:####.................................... 10.0%
Percent Complete:########................................ 20.0%
Percent Complete:############............................ 30.0%
Percent Complete:################........................ 40.0%
Percent Complete:####################.................... 50.0%
Percent Complete:########################................ 60.0%
Percent Complete:############################............ 70.0%
Percent Complete:################################........ 80.0%
Percent Complete:####################################.... 90.0%
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(
Percent Complete:####.................................... 10.0%
Percent Complete:################........................ 40.0%
Percent Complete:####################.................... 50.0%
Percent Complete:########################................ 60.0%
Percent Complete:####################################.... 90.0%
Percent Complete:######################################## 100.0%
PyAEDT INFO: Done...
PyAEDT INFO: Viewing Geometry...
PyAEDT INFO: Step file C:\Users\ansys\AppData\Local\Temp\tmpdpwnzar7.ansys\city.pyaedt\Ansys\terrain.stl imported
PyAEDT INFO: Step file C:\Users\ansys\AppData\Local\Temp\tmpdpwnzar7.ansys\city.pyaedt\Ansys\buildings.stl imported
[6]:
{'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\\tmpdpwnzar7.ansys\\city.pyaedt\\Ansys/terrain.stl',
   'color': 'brown',
   'material': 'earth'},
  'buildings': {'file_name': 'C:\\Users\\ansys\\AppData\\Local\\Temp\\tmpdpwnzar7.ansys\\city.pyaedt\\Ansys\\buildings.stl',
   'color': 'grey',
   'material': 'concrete'},
  'roads': {'file_name': 'C:\\Users\\ansys\\AppData\\Local\\Temp\\tmpdpwnzar7.ansys\\city.pyaedt\\Ansys\\roads.stl',
   'color': 'black',
   'material': 'asphalt'}}}

Visualize the model#

Plot the model.

[7]:
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\tmpdpwnzar7.ansys\city.aedt.
PyAEDT INFO: File C:\Users\ansys\AppData\Local\Temp\tmpdpwnzar7.ansys\city.aedt correctly loaded. Elapsed time: 0m 0sec
PyAEDT INFO: aedt file load time 0.01565074920654297
PyAEDT INFO: PostProcessor class has been initialized! Elapsed time: 0m 0sec
PyAEDT INFO: PostProcessor class has been initialized! Elapsed time: 0m 0sec
PyAEDT INFO: Post class has been initialized! Elapsed time: 0m 0sec
[7]:
True

Finish#

Save the project#

Release AEDT and close the example.

[8]:
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.

[9]:
temp_folder.cleanup()

Download this example

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