.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/00_basic/example_02_capture_images.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_00_basic_example_02_capture_images.py: .. _ref_example_02_capture_images: Capture images after a solve ---------------------------- Using supplied files, this example shows how to resume a MECHDAT file and capture the images of all results in a folder on the disk. .. GENERATED FROM PYTHON SOURCE LINES 12-16 Download required files ~~~~~~~~~~~~~~~~~~~~~~~ Download the required files. Print the file paths for the MECHDAT file and script files. .. GENERATED FROM PYTHON SOURCE LINES 16-34 .. code-block:: Python import os from ansys.mechanical.core import launch_mechanical from ansys.mechanical.core.examples import download_file from matplotlib import image as mpimg from matplotlib import pyplot as plt mechdat_path = download_file( "example_03_simple_bolt_new.mechdat", "pymechanical", "00_basic" ) print(f"Downloaded the MECHDAT file to: {mechdat_path}") script_file_path = download_file( "example_02_capture_images_helper.py", "pymechanical", "00_basic" ) print(f"Downloaded the script files to: {script_file_path}") .. rst-class:: sphx-glr-script-out .. code-block:: none Downloaded the MECHDAT file to: /home/runner/.local/share/ansys_mechanical_core/examples/example_03_simple_bolt_new.mechdat Downloaded the script files to: /home/runner/.local/share/ansys_mechanical_core/examples/example_02_capture_images_helper.py .. GENERATED FROM PYTHON SOURCE LINES 35-40 Launch Mechanical ~~~~~~~~~~~~~~~~~ Launch a new Mechanical session in batch, setting the ``cleanup_on_exit`` argument to ``False``. To close this Mechanical session when finished, this example must call the ``mechanical.exit()`` method. .. GENERATED FROM PYTHON SOURCE LINES 40-44 .. code-block:: Python mechanical = launch_mechanical(batch=True, cleanup_on_exit=False) print(mechanical) .. rst-class:: sphx-glr-script-out .. code-block:: none Ansys Mechanical [Ansys Mechanical Enterprise] Product Version:242 Software build date: 06/03/2024 09:35:09 .. GENERATED FROM PYTHON SOURCE LINES 45-49 Initialize the variable needed for opening the MECHDAT file ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Set the ``mechdat_path`` variable for later use. Make the variable compatible for Windows, Linux, and Docker containers. .. GENERATED FROM PYTHON SOURCE LINES 49-66 .. code-block:: Python project_directory = mechanical.project_directory print(f"project directory = {project_directory}") # Upload the file to the project directory. mechanical.upload(file_name=mechdat_path, file_location_destination=project_directory) # Build the path relative to the project directory. base_name = os.path.basename(mechdat_path) combined_path = os.path.join(project_directory, base_name) mechdat_path_modified = combined_path.replace("\\", "\\\\") mechanical.run_python_script(f"mechdat_path='{mechdat_path_modified}'") # Verify the path for the MECHDAT file. result = mechanical.run_python_script(f"mechdat_path") print(f"MECHDATA file is stored on the server at: {result}") .. rst-class:: sphx-glr-script-out .. code-block:: none project directory = /tmp/ANSYS.root.1/AnsysMech7355/Project_Mech_Files/ Uploading example_03_simple_bolt_new.mechdat to dns:///127.0.0.1:10000:/tmp/ANSYS.root.1/AnsysMech7355/Project_Mech_Files/.: 0%| | 0.00/7.06M [00:00` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_02_capture_images.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: example_02_capture_images.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_