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.12.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_787eea3e-8729-47a9-8ab7-a678cf1ff20a.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 58744
PyAEDT INFO: AEDT installation Path C:\Program Files\AnsysEM\v242\Win64
PyAEDT INFO: Ansoft.ElectronicsDesktop.2024.2 version started with process ID 1840.
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: T
PyAEDT INFO: 17
PyAEDT INFO: (570712.4249784308, 4458470.643280741, 17, 'T')
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\tmp6tin72vm.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\tmp6tin72vm.ansys\city.pyaedt\Ansys/terrain.stl imported
PyAEDT INFO: Step file C:\Users\ansys\AppData\Local\Temp\tmp6tin72vm.ansys\city.pyaedt\Ansys\buildings.stl imported
PyAEDT INFO: Step file C:\Users\ansys\AppData\Local\Temp\tmp6tin72vm.ansys\city.pyaedt\Ansys\roads.stl imported
[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\\tmp6tin72vm.ansys\\city.pyaedt\\Ansys/terrain.stl',
'color': 'brown',
'material': 'earth'},
'buildings': {'file_name': 'C:\\Users\\ansys\\AppData\\Local\\Temp\\tmp6tin72vm.ansys\\city.pyaedt\\Ansys\\buildings.stl',
'color': 'grey',
'material': 'concrete'},
'roads': {'file_name': 'C:\\Users\\ansys\\AppData\\Local\\Temp\\tmp6tin72vm.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/tmp6tin72vm.ansys/city.aedt.
PyAEDT INFO: File C:/Users/ansys/AppData/Local/Temp/tmp6tin72vm.ansys/city.aedt correctly loaded. Elapsed time: 0m 0sec
PyAEDT INFO: aedt file load time 0.015625715255737305
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(
[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.