.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/050-save-session-and-workspace.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_050-save-session-and-workspace.py: .. _save_session_and_workspace_example: Save sessions and workspace templates ====================================== This example demonstrates how to save Result Explorer sessions and workspace templates for later reuse: - **Session saving** to capture the complete state of all workspaces and solutions. - **Workspace templates** to save individual workspace layouts and configurations. - **Template export** for sharing and reusing visualization configurations. - **Multiple workspace management** with different views and layouts. This example uses a transient structural analysis result to create multiple workspaces and save them as templates along with the complete session. .. GENERATED FROM PYTHON SOURCE LINES 36-37 Import the Result Explorer dependencies. .. GENERATED FROM PYTHON SOURCE LINES 37-44 .. code-block:: Python import tempfile from pathlib import Path from ansys.result_explorer.core import launch_result_explorer from ansys.result_explorer.core.examples import ExampleKeys, get_example_file from ansys.result_explorer.core.models import ViewType .. GENERATED FROM PYTHON SOURCE LINES 45-48 Launch Result Explorer ---------------------- Start a Result Explorer instance for this example. .. GENERATED FROM PYTHON SOURCE LINES 48-50 .. code-block:: Python rx = launch_result_explorer() .. GENERATED FROM PYTHON SOURCE LINES 51-54 Create a solution ------------------ Load the transient structural analysis result file. .. GENERATED FROM PYTHON SOURCE LINES 54-62 .. code-block:: Python rst_path = get_example_file(ExampleKeys.RST_CP_TRANSIENT) sol = rx.create_solution( name="Transient Analysis", file_path=rst_path, ) print(f"Created solution: {sol.name}") .. rst-class:: sphx-glr-script-out .. code-block:: none Created solution: Transient Analysis .. GENERATED FROM PYTHON SOURCE LINES 63-66 Retrieve available views ------------------------- Get the available views from the solution for use in workspaces. .. GENERATED FROM PYTHON SOURCE LINES 66-75 .. code-block:: Python views = sol.views print(f"Available views: {len(views)}") for v in views: print(f" - {v.name}") # Get displacement and stress views for the workspaces disp_view = next((v for v in views if "Displacement" in v.name), None) stress_view = next((v for v in views if "Stress" in v.name), None) .. rst-class:: sphx-glr-script-out .. code-block:: none Available views: 13 - Logs - Convergence Trackers - Contact Trackers - Mesh - Displacement - Equivalent Stress (von-Mises) - Contact Status - Newton-Raphson Residual - Temperature - Total Heat Flux - Min/Max Displacement Over Time - Min/Max Equivalent Stress Over Time - Temperature Over Time .. GENERATED FROM PYTHON SOURCE LINES 76-79 Delete the default workspace ---------------------------- Remove the default "Workspace 1" that is created automatically. .. GENERATED FROM PYTHON SOURCE LINES 79-84 .. code-block:: Python default_workspaces = [ws for ws in rx.list_workspaces() if ws.name == "Workspace 1"] for ws in default_workspaces: rx.delete_workspace(workspace=ws) print(f"Deleted default workspace: {ws.name}") .. rst-class:: sphx-glr-script-out .. code-block:: none Deleted default workspace: Workspace 1 .. GENERATED FROM PYTHON SOURCE LINES 85-88 Create first workspace with displacement view ----------------------------------------------- Create a workspace and configure it with displacement visualization. .. GENERATED FROM PYTHON SOURCE LINES 88-99 .. code-block:: Python workspace_1 = rx.create_workspace(name="Displacement Workspace") print(f"\nCreated workspace 1: {workspace_1.name}") if disp_view: viewport_1 = workspace_1.assign_view(view=disp_view, wait=True) print(f" Assigned view: {disp_view.name}") else: print(" No displacement view found, using first available view") if views: viewport_1 = workspace_1.assign_view(view=views[0], wait=True) .. rst-class:: sphx-glr-script-out .. code-block:: none Created workspace 1: Displacement Workspace Assigned view: Displacement .. GENERATED FROM PYTHON SOURCE LINES 100-103 Create second workspace with stress view ------------------------------------------ Create another workspace with a different view layout. .. GENERATED FROM PYTHON SOURCE LINES 103-120 .. code-block:: Python workspace_2 = rx.create_workspace(name="Stress Workspace", rows=1, cols=2) print(f"Created workspace 2: {workspace_2.name} ({len(workspace_2.viewport_ids)} viewports)") if stress_view: viewport_2 = workspace_2.assign_view(view=stress_view, wait=True) print(f" Assigned view: {stress_view.name}") else: print(" No stress view found, using first available view") if views: viewport_2 = workspace_2.assign_view(view=views[0], wait=True) # Assign a logs view to the second viewport logs_view = next((v for v in views if v.type == ViewType.VIEW_TYPE_LOGS), None) viewport_2 = workspace_2.viewports[1] viewport_2.set_view(logs_view, wait=True) print(f" Assigned view to second viewport: {logs_view.name}") .. rst-class:: sphx-glr-script-out .. code-block:: none Created workspace 2: Stress Workspace (2 viewports) Assigned view: Equivalent Stress (von-Mises) Assigned view to second viewport: Logs .. GENERATED FROM PYTHON SOURCE LINES 121-125 Save session and workspace templates ---------------------------------------- Save the complete session and export each workspace as a template to a temporary directory. .. GENERATED FROM PYTHON SOURCE LINES 125-143 .. code-block:: Python temp_dir = Path(tempfile.gettempdir()) / "result_explorer_example" temp_dir.mkdir(exist_ok=True) # Save the complete session session_path = temp_dir / "my_session.rxs" rx.save_session(str(session_path)) print(f"\nSaved session to: {session_path}") # Export each workspace as a template for workspace in rx.list_workspaces(): template_path = temp_dir / f"{workspace.name}.rxwt" workspace.export_as_template(str(template_path)) print(f"Saved workspace template: {template_path}") print(f"\nAll files saved to: {temp_dir}") rx.stop() .. rst-class:: sphx-glr-script-out .. code-block:: none Saved session to: /tmp/result_explorer_example/my_session.rxs Saved workspace template: /tmp/result_explorer_example/Displacement Workspace.rxwt Saved workspace template: /tmp/result_explorer_example/Stress Workspace.rxwt All files saved to: /tmp/result_explorer_example .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 20.654 seconds) .. _sphx_glr_download_examples_050-save-session-and-workspace.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 050-save-session-and-workspace.ipynb <050-save-session-and-workspace.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 050-save-session-and-workspace.py <050-save-session-and-workspace.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 050-save-session-and-workspace.zip <050-save-session-and-workspace.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_