.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\adaptive_library\RoundParallelSlotBttm.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_adaptive_library_RoundParallelSlotBttm.py: Round Parallel Slot Bottom ========================== This script applies the adaptive templates functionality to modify parallel slot bottoms from having square corners to round corners. .. GENERATED FROM PYTHON SOURCE LINES 30-36 Perform required imports ------------------------ Import ``pymotorcad`` to access Motor-CAD. Import ``draw_objects_debug`` to plot figures of geometry objects. Import ``os``, ``shutil``, ``sys``, and ``tempfile`` to open and save a temporary .mot file if none is open. .. GENERATED FROM PYTHON SOURCE LINES 36-45 .. code-block:: Python import os import shutil import sys import tempfile import ansys.motorcad.core as pymotorcad from ansys.motorcad.core.geometry_drawing import draw_objects_debug .. GENERATED FROM PYTHON SOURCE LINES 47-57 Connect to Motor-CAD -------------------- If this script is loaded into the Adaptive Templates file in Motor-CAD, the current Motor-CAD instance is used. If the script is run externally, these actions occur: a new Motor-CAD instance is opened, the e3 WFSM motor template is loaded, the **Slot Type** is set to **Parallel Slot** and the file is saved to a temporary folder. To keep a new Motor-CAD instance open after executing the script, use the ``MotorCAD(keep_instance_open=True)`` option when opening the new instance. Alternatively, use the ``MotorCAD()`` method, which closes the Motor-CAD instance after the script is executed. .. GENERATED FROM PYTHON SOURCE LINES 57-83 .. code-block:: Python if pymotorcad.is_running_in_internal_scripting(): # Use existing Motor-CAD instance if possible mc = pymotorcad.MotorCAD(open_new_instance=False) else: mc = pymotorcad.MotorCAD(keep_instance_open=True) # Disable popup messages mc.set_variable("MessageDisplayState", 2) mc.set_visible(True) mc.load_template("e3") mc.set_variable("SlotType", 2) # Open relevant file working_folder = os.path.join(tempfile.gettempdir(), "adaptive_library") try: shutil.rmtree(working_folder) except: pass os.mkdir(working_folder) mot_name = "e3_WFSM_Round_Parallel_Slot" mc.save_to_file(working_folder + "/" + mot_name + ".mot") # Reset geometry to default mc.reset_adaptive_geometry() .. GENERATED FROM PYTHON SOURCE LINES 84-90 Define necessary functions -------------------------- Set adaptive parameter if required ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The ``set_default_parameter`` function is defined to check if a parameter exists. If not, it creates the parameter with a default value. .. GENERATED FROM PYTHON SOURCE LINES 90-97 .. code-block:: Python def set_default_parameter(parameter_name, default_value): try: mc.get_adaptive_parameter_value(parameter_name) except pymotorcad.MotorCADError: mc.set_adaptive_parameter_value(parameter_name, default_value) .. GENERATED FROM PYTHON SOURCE LINES 98-104 Get required parameters and objects ----------------------------------- From Motor-CAD, get the adaptive parameters and their values. Use the ``set_default_parameter`` method to set the required ``Slot Bttm Corner Radius`` parameter if undefined. .. GENERATED FROM PYTHON SOURCE LINES 104-106 .. code-block:: Python set_default_parameter("Slot Bttm Corner Radius", 0.5) .. GENERATED FROM PYTHON SOURCE LINES 107-108 Get the slot bottom corner radius adaptive parameter value. .. GENERATED FROM PYTHON SOURCE LINES 108-110 .. code-block:: Python radius = mc.get_adaptive_parameter_value("Slot Bttm Corner Radius") .. GENERATED FROM PYTHON SOURCE LINES 111-113 Get the standard template regions with corners to be rounded. These can be drawn for debugging if required. .. GENERATED FROM PYTHON SOURCE LINES 113-120 .. code-block:: Python stator = mc.get_region("Stator") winding_1 = mc.get_region("ArmatureSlotL1") winding_2 = mc.get_region("ArmatureSlotR1") stator_slot = mc.get_region("StatorSlot") liner = mc.get_region("Liner") impreg = mc.get_region("Impreg") .. GENERATED FROM PYTHON SOURCE LINES 121-123 Get the slot corner coordinates to be rounded. Plot the corner coordinates and the stator region using the ``draw_objects_debug`` function to ensure you have selected the correct points. .. GENERATED FROM PYTHON SOURCE LINES 123-126 .. code-block:: Python corners = [stator.entities[5].end, stator.entities[7].end] draw_objects_debug([stator, corners[0], corners[1]]) .. image-sg:: /examples/adaptive_library/images/sphx_glr_RoundParallelSlotBttm_001.png :alt: RoundParallelSlotBttm :srcset: /examples/adaptive_library/images/sphx_glr_RoundParallelSlotBttm_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 127-129 Define the impregration corner coordinates to be rounded. Draw the impregnation region and corner coordinates using the ``draw_objects_debug`` function. .. GENERATED FROM PYTHON SOURCE LINES 129-132 .. code-block:: Python impreg_corners = [impreg.entities[1].end, impreg.entities[3].end] draw_objects_debug([stator, impreg, impreg_corners[0], impreg_corners[1]]) .. image-sg:: /examples/adaptive_library/images/sphx_glr_RoundParallelSlotBttm_002.png :alt: RoundParallelSlotBttm :srcset: /examples/adaptive_library/images/sphx_glr_RoundParallelSlotBttm_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 133-138 Create the Adaptive Templates geometry -------------------------------------- Round the slot bottom corners for all regions that share these corner coordinates using the ``Region.round_corners`` method. Armature winding regions only have 1 of the two corners, so use the ``Region.round_corner`` method for these regions. .. GENERATED FROM PYTHON SOURCE LINES 138-144 .. code-block:: Python stator.round_corners(corners, radius) stator_slot.round_corners(corners, radius) liner.round_corners(corners, radius) winding_1.round_corner(corners[1], radius) winding_2.round_corner(corners[0], radius) .. GENERATED FROM PYTHON SOURCE LINES 145-147 Round the impregnation corners for the liner and impregnation regions using the ``Region.round_corners`` method. .. GENERATED FROM PYTHON SOURCE LINES 147-150 .. code-block:: Python liner.round_corners(impreg_corners, radius) impreg.round_corners(impreg_corners, radius) .. GENERATED FROM PYTHON SOURCE LINES 151-152 Set the edited regions in Motor-CAD. .. GENERATED FROM PYTHON SOURCE LINES 152-159 .. code-block:: Python mc.set_region(stator) mc.set_region(stator_slot) mc.set_region(winding_1) mc.set_region(winding_2) mc.set_region(liner) mc.set_region(impreg) .. GENERATED FROM PYTHON SOURCE LINES 160-162 .. image:: ../../images/adaptive_templates/RoundParSlotBttm.png :width: 600pt .. GENERATED FROM PYTHON SOURCE LINES 164-174 Load in Adaptive Templates script if required --------------------------------------------- When this script is run externally, the script executes the following: * Set **Geometry type** to **Adaptive**. * Load the script into the **Adaptive Templates** tab. * Go to the **Geometry -> Radial** tab to run the Adaptive Templates script and display the new geometry. .. GENERATED FROM PYTHON SOURCE LINES 176-179 .. note:: When running in a Jupyter Notebook, you must provide the path for the Adaptive Templates script (PY file) instead of ``sys.argv[0]`` when using the ``load_adaptive_script()`` method. .. GENERATED FROM PYTHON SOURCE LINES 179-183 .. code-block:: Python if not pymotorcad.is_running_in_internal_scripting(): mc.set_variable("GeometryTemplateType", 1) mc.load_adaptive_script(sys.argv[0]) mc.display_screen("Geometry;Radial") .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 43.470 seconds) .. _sphx_glr_download_examples_adaptive_library_RoundParallelSlotBttm.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: RoundParallelSlotBttm.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: RoundParallelSlotBttm.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: RoundParallelSlotBttm.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_