.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/basic/example_09_tracemapping.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_basic_example_09_tracemapping.py: .. _ref_example_09: Trace Mapping Example --------------------- Using the provided file, this example demonstrates how to import trace map data into a static structural analysis of a new Mechanical session and execute a sequence of Python scripting commands to mesh the model and export an image. .. GENERATED FROM PYTHON SOURCE LINES 13-15 Import necessary libraries ~~~~~~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 15-23 .. 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 .. GENERATED FROM PYTHON SOURCE LINES 24-29 Launch mechanical ~~~~~~~~~~~~~~~~~ Launch a new Mechanical session in batch, setting ``cleanup_on_exit`` to ``False``. To close this Mechanical session when finished, this example must call the ``mechanical.exit()`` method. .. GENERATED FROM PYTHON SOURCE LINES 29-34 .. 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 35-38 Download the required files ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Download files and print path .. GENERATED FROM PYTHON SOURCE LINES 38-69 .. code-block:: Python all_input_files = { "geometry_file_name": "example_09_pcb.agdb", "def_file": "example_09_edb.def", "copper_alloy_material_file": "example_09_mat_copper_alloy.xml", "fr4_material_file": "example_09_mat_fr4.xml", } project_directory = mechanical.project_directory print(f"project directory = {project_directory}") for file_type, file_name in all_input_files.items(): file_path = download_file(file_name, "pymechanical", "00_basic") print(f"Downloaded the {file_type} to: {file_path}") # Upload the file to the project directory. mechanical.upload(file_name=file_path, file_location_destination=project_directory) # Build the path relative to project directory. base_name = os.path.basename(file_path) combined_path = os.path.join(project_directory, base_name) part_file_path = combined_path.replace("\\", "\\\\") mechanical.run_python_script(f"{file_type} = '{part_file_path}'") result = mechanical.run_python_script(f"{file_type}") print(f"path of {file_type} on server: {result}") png_image_name = "myplot.png" mechanical.run_python_script(f"image_name='{png_image_name}'") .. rst-class:: sphx-glr-script-out .. code-block:: none project directory = /tmp/ANSYS.root.1/AnsysMech8C1A/Project_Mech_Files/ Downloaded the geometry_file_name to: /home/runner/.local/share/ansys_mechanical_core/examples/example_09_pcb.agdb Uploading example_09_pcb.agdb to dns:///127.0.0.1:10000:/tmp/ANSYS.root.1/AnsysMech8C1A/Project_Mech_Files/.: 0%| | 0.00/2.27M [00:00` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_09_tracemapping.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: example_09_tracemapping.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_