.. 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 32-33 Perform required imports .. GENERATED FROM PYTHON SOURCE LINES 33-35 .. code-block:: Python import ansys.motorcad.core as pymotorcad .. GENERATED FROM PYTHON SOURCE LINES 36-37 Launch Motor-CAD .. GENERATED FROM PYTHON SOURCE LINES 37-67 .. 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 68-71 PyMotorCAD Documentation Example -------------------------------------- (Used for the PyMotorCAD Documentation Examples only) .. GENERATED FROM PYTHON SOURCE LINES 71-77 .. 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 2:55:50 PM : Loaded script file: mechanical_stress.py 2:55:53 PM : Python script output: Max Stress: 5.36337772082974 Safety factor is: 84.835 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 40.719 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 ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: mechanical_stress.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_