.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\03-Maxwell\Maxwell3D_Segmentation.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_03-Maxwell_Maxwell3D_Segmentation.py: Maxwell 3D: magnet segmentation ------------------------------- This example shows how you can use PyAEDT to segment magnets of an electric motor. The method is valid and usable for any object the user would like to segment. .. GENERATED FROM PYTHON SOURCE LINES 8-11 Perform required imports ~~~~~~~~~~~~~~~~~~~~~~~~ Perform required imports. .. GENERATED FROM PYTHON SOURCE LINES 11-16 .. code-block:: default from pyaedt import downloads from pyaedt import generate_unique_folder_name from pyaedt import Maxwell3d .. GENERATED FROM PYTHON SOURCE LINES 17-21 Set non-graphical mode ~~~~~~~~~~~~~~~~~~~~~~ Set non-graphical mode. You can set ``non_graphical`` either to ``True`` or ``False``. .. GENERATED FROM PYTHON SOURCE LINES 21-24 .. code-block:: default non_graphical = False .. GENERATED FROM PYTHON SOURCE LINES 25-28 Download .aedt file example ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Set local temporary folder to export the .aedt file to. .. GENERATED FROM PYTHON SOURCE LINES 28-31 .. code-block:: default temp_folder = generate_unique_folder_name() aedt_file = downloads.download_file("object_segmentation", "Motor3D_obj_segments.aedt", temp_folder) .. GENERATED FROM PYTHON SOURCE LINES 32-35 Launch Maxwell 3D ~~~~~~~~~~~~~~~~~ Launch Maxwell 3D. .. GENERATED FROM PYTHON SOURCE LINES 35-41 .. code-block:: default m3d = Maxwell3d(projectname=aedt_file, specified_version="2023.2", new_desktop_session=True, non_graphical=non_graphical) .. rst-class:: sphx-glr-script-out .. code-block:: none Initializing new desktop! C:\actions-runner\_work\_tool\Python\3.10.5\x64\lib\subprocess.py:1070: ResourceWarning: subprocess 720 is still running _warn("subprocess %s is still running" % self.pid, .. GENERATED FROM PYTHON SOURCE LINES 42-45 Create object to access 3D modeler ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Create the object ``mod3D`` to access the 3D modeler easily. .. GENERATED FROM PYTHON SOURCE LINES 45-48 .. code-block:: default modeler = m3d.modeler .. GENERATED FROM PYTHON SOURCE LINES 49-57 Segment first magnet by specifying the number of segments ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Select first magnet to segment by specifying the number of segments. The method accepts in input either the list of magnets names to segment or magnets ids or the magnet object :class:`pyaedt.modeler.cad.object3d.Object3d`. ``apply_mesh_sheets`` is enabled which means that the mesh sheets will be applied in the geometry too. In this specific case we give as input the name of the magnet. .. GENERATED FROM PYTHON SOURCE LINES 57-62 .. code-block:: default segments_number = 5 object_name = "PM_I1" sheets_1 = modeler.objects_segmentation(object_name, segments_number=segments_number, apply_mesh_sheets=True) .. GENERATED FROM PYTHON SOURCE LINES 63-67 Segment second magnet by specifying the number of segments ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Select second magnet to segment by specifying the number of segments. In this specific case we give as input the id of the magnet. .. GENERATED FROM PYTHON SOURCE LINES 67-73 .. code-block:: default segments_number = 4 object_name = "PM_I1_1" magnet_id = [obj.id for obj in modeler.object_list if obj.name == object_name][0] sheets_2 = modeler.objects_segmentation(magnet_id, segments_number=segments_number, apply_mesh_sheets=True) .. GENERATED FROM PYTHON SOURCE LINES 74-78 Segment third magnet by specifying the segmentation thickness ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Select third magnet to segment by specifying the segmentation thickness. In this specific case we give as input the magnet object of type :class:`pyaedt.modeler.cad.object3d.Object3d`. .. GENERATED FROM PYTHON SOURCE LINES 78-84 .. code-block:: default segmentation_thickness = 1 object_name = "PM_O1" magnet = [obj for obj in modeler.object_list if obj.name == object_name][0] sheets_3 = modeler.objects_segmentation(magnet, segmentation_thickness=segmentation_thickness, apply_mesh_sheets=True) .. GENERATED FROM PYTHON SOURCE LINES 85-89 Segment fourth magnet by specifying the number of segments ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Select fourth magnet to segment by specifying the number of segments. In this specific case we give as input the name of the magnet and we disable the mesh sheets. .. GENERATED FROM PYTHON SOURCE LINES 89-94 .. code-block:: default object_name = "PM_O1_1" segments_number = 10 sheets_4 = modeler.objects_segmentation(object_name, segments_number=segments_number) .. GENERATED FROM PYTHON SOURCE LINES 95-98 Save project and close AEDT ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Save the project and close AEDT. .. GENERATED FROM PYTHON SOURCE LINES 98-101 .. code-block:: default m3d.save_project() m3d.release_desktop() .. rst-class:: sphx-glr-script-out .. code-block:: none True .. rst-class:: sphx-glr-timing **Total running time of the script:** (1 minutes 10.615 seconds) .. _sphx_glr_download_examples_03-Maxwell_Maxwell3D_Segmentation.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: Maxwell3D_Segmentation.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: Maxwell3D_Segmentation.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_