Download this example
Download this example as a Jupyter Notebook or as a Python script.
Magnet segmentation#
This example shows how to use PyAEDT to segment magnets of an electric motor. The method is valid and usable for any object you would like to segment.
Keywords: Maxwell 3D, Magnet segmentation.
Perform imports and define constants#
Perform required imports.
[1]:
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")
Download AEDT file example#
Set the local temporary folder to export the AEDT file to.
[5]:
aedt_file = ansys.aedt.core.downloads.download_file(
source="object_segmentation",
name="Motor3D_obj_segments.aedt",
destination=temp_folder.name,
)
Launch Maxwell 3D#
Launch Maxwell 3D, providing the version, rgw path to the project, and the graphical mode.
[6]:
m3d = ansys.aedt.core.Maxwell3d(
project=aedt_file,
version=AEDT_VERSION,
new_desktop=True,
non_graphical=NG_MODE,
)
PyAEDT INFO: Parsing C:\Users\ansys\AppData\Local\Temp\tmpuhccrifg.ansys\object_segmentation\Motor3D_obj_segments.aedt.
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_8fe8ed27-9425-4a38-97a5-97ec864f70ba.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 55277
PyAEDT INFO: File C:\Users\ansys\AppData\Local\Temp\tmpuhccrifg.ansys\object_segmentation\Motor3D_obj_segments.aedt correctly loaded. Elapsed time: 0m 0sec
PyAEDT INFO: AEDT installation Path C:\Program Files\AnsysEM\v242\Win64
PyAEDT INFO: Ansoft.ElectronicsDesktop.2024.2 version started with process ID 6416.
PyAEDT INFO: Project Motor3D_obj_segments has been opened.
PyAEDT INFO: Active Design set to Maxwell3DDesign1
PyAEDT INFO: Aedt Objects correctly read
Segment first magnet by specifying number of segments#
Select the first magnet to segment by specifying the number of segments. The method accepts as input the list of magnets names to segment, magnet IDs, or the magnet :class:ansys.aedt.core.modeler.cad.object3d.Object3d
object. When apply_mesh_sheets
is enabled, the mesh sheets are also applied in the geometry. In the following code, the name of the magnet is also given as an input.
[7]:
segments_number = 2
object_name = "PM_I1"
sheets_1 = m3d.modeler.objects_segmentation(
object_name,
segments=segments_number,
apply_mesh_sheets=True,
mesh_sheets=3,
)
PyAEDT INFO: Modeler class has been initialized! Elapsed time: 0m 1sec
PyAEDT INFO: Parsing design objects. This operation can take time
PyAEDT INFO: 3D Modeler objects parsed. Elapsed time: 0m 0sec
Segment second magnet by specifying number of segments#
Select the second magnet to segment by specifying the number of segments. The following code gives the ID of the magnet as an input.
[8]:
segments_number = 2
object_name = "PM_I1_1"
magnet_id = [obj.id for obj in m3d.modeler.object_list if obj.name == object_name][0]
sheets_2 = m3d.modeler.objects_segmentation(
magnet_id, segments=segments_number, apply_mesh_sheets=True
)
Segment third magnet by specifying segmentation thickness#
Select the third magnet to segment by specifying the segmentation thickness. The following code gives the magnet object type ansys.aedt.core.modeler.cad.object3d.Object3d
as an input.
[9]:
segmentation_thickness = 1
object_name = "PM_O1"
magnet = [obj for obj in m3d.modeler.object_list if obj.name == object_name][0]
sheets_3 = m3d.modeler.objects_segmentation(
magnet, segmentation_thickness=segmentation_thickness, apply_mesh_sheets=True
)
Segment fourth magnet by specifying number of segments#
Select the fourth magnet to segment by specifying the number of segments. The following code gives the name of the magnet as input and disables the mesh sheets.
[10]:
object_name = "PM_O1_1"
segments_number = 2
sheets_4 = m3d.modeler.objects_segmentation(object_name, segments=segments_number)
Release AEDT#
[11]:
m3d.save_project()
m3d.release_desktop()
# Wait 3 seconds to allow AEDT to shut down before cleaning the temporary directory.
time.sleep(3)
PyAEDT INFO: Project Motor3D_obj_segments 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.
[12]:
temp_folder.cleanup()
Download this example
Download this example as a Jupyter Notebook or as a Python script.