.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\internal_scripting\mechanical_stress.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_internal_scripting_mechanical_stress.py: .. _ref_internal_scripting_mechanical_stress: Mechanical stress ================= This example demonstrates internal scripting mechanical stress functionality .. GENERATED FROM PYTHON SOURCE LINES 10-11 Perform required imports .. GENERATED FROM PYTHON SOURCE LINES 11-13 .. code-block:: Python import ansys.motorcad.core as pymotorcad .. GENERATED FROM PYTHON SOURCE LINES 14-15 Launch Motor-CAD .. GENERATED FROM PYTHON SOURCE LINES 15-45 .. code-block:: Python mc = pymotorcad.MotorCAD() # This function is called when "Run" is pressed def main(): pass class mechanical_stress: def initial(self): # %% # Disable pop-up messages mc.set_variable("MessageDisplayState", 2) # Called before calculation mc.set_variable("ShaftSpeed", 1500) def final(self): # Called after calculation yield_stress = mc.get_variable("YieldStress_RotorLam") max_stress = mc.get_variable("MaxStress_RotorLam") print("Max Stress: " + str(max_stress)) safety_factor = yield_stress / max_stress print("Safety factor is: " + str(round(safety_factor, 3))) mc.set_variable("MessageDisplayState", 0) .. GENERATED FROM PYTHON SOURCE LINES 46-49 PyMotorCAD Documentation Example -------------------------------------- (Used for the PyMotorCAD Documentation Examples only) .. GENERATED FROM PYTHON SOURCE LINES 49-55 .. code-block:: Python try: from setup_scripts.setup_script import run_mech_stress_demo except ImportError: pass else: run_mech_stress_demo(mc) .. rst-class:: sphx-glr-script-out .. code-block:: none 11:34:16 AM : Python script output: Max Stress: 5.35814481045248 11:34:16 AM : Python script output: Safety factor is: 84.917 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 23.860 seconds) .. _sphx_glr_download_examples_internal_scripting_mechanical_stress.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: mechanical_stress.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: mechanical_stress.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_