diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index ec945b8a7..253c254d3 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -635,7 +635,7 @@ jobs: run: | . /env/bin/activate pip install uv - uv pip install -e .[doc] + uv pip install -e .[doc,graphics] - name: Build docs env: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index aac96c2c0..ca7a33503 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -63,7 +63,7 @@ repos: tests/scripts/run_python_error.py | tests/scripts/run_python_success.py | tests/scripts/log_message.py | - examples/embedding_n_remote/embedding_remote.py + examples/.* )$ - repo: https://github.com/pre-commit/pre-commit-hooks diff --git a/doc/changelog.d/1125.test.md b/doc/changelog.d/1125.test.md new file mode 100644 index 000000000..d36d7a952 --- /dev/null +++ b/doc/changelog.d/1125.test.md @@ -0,0 +1 @@ +Example refactor \ No newline at end of file diff --git a/doc/source/conf.py b/doc/source/conf.py index 946324156..ed626381e 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -13,6 +13,8 @@ import warnings from ansys_sphinx_theme import ansys_favicon, get_version_match +import pyvista +from pyvista.plotting.utilities.sphinx_gallery import DynamicScraper from sphinx_gallery.sorting import FileNameSortKey import ansys.mechanical.core as pymechanical @@ -20,6 +22,8 @@ # necessary when building the sphinx gallery pymechanical.BUILDING_GALLERY = True +pyvista.BUILDING_GALLERY = True +pyvista.OFF_SCREEN = True # Whether or not to build the cheatsheet BUILD_CHEATSHEET = True if os.environ.get("BUILD_EXAMPLES", "true") == "true" else False @@ -61,6 +65,7 @@ "sphinx_copybutton", "sphinx_design", "sphinxemoji.sphinxemoji", + "pyvista.ext.viewer_directive", ] if pymechanical.BUILDING_GALLERY: @@ -175,7 +180,7 @@ "backreferences_dir": None, # Modules for which function level galleries are created. In "doc_module": "ansys-mechanical-core", - "image_scrapers": ("matplotlib"), + "image_scrapers": (DynamicScraper(), "matplotlib"), "ignore_pattern": "flycheck*", "thumbnail_size": (350, 350), } diff --git a/doc/source/index.rst b/doc/source/index.rst index 9419d91b9..7246d1b71 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -31,7 +31,7 @@ Python API to interact with `Ansys Mechanical`_ (FEA software for structural eng .. grid-item-card:: Examples :fa:`scroll` :padding: 2 2 2 2 - :link: examples/index + :link: examples/gallery_examples/index :link-type: doc Dive into examples created using PyMechanical. @@ -109,7 +109,7 @@ Python API to interact with `Ansys Mechanical`_ (FEA software for structural eng :maxdepth: 3 getting_started/index - examples/index + examples/gallery_examples/index user_guide_session/index user_guide_embedding/index user_guide_scripting/index diff --git a/examples/00_tips/readme.txt b/examples/00_tips/readme.txt new file mode 100644 index 000000000..2439d4a82 --- /dev/null +++ b/examples/00_tips/readme.txt @@ -0,0 +1,5 @@ +Tips +==== + +This section showcases some of the useful functions that can be used +in PyMechanical embedding workflow. diff --git a/examples/00_tips/tips_01.py b/examples/00_tips/tips_01.py new file mode 100644 index 000000000..dae8602bc --- /dev/null +++ b/examples/00_tips/tips_01.py @@ -0,0 +1,78 @@ +# Copyright (C) 2022 - 2025 ANSYS, Inc. and/or its affiliates. +# SPDX-License-Identifier: MIT +# +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +""".. _ref_tips_01: + +3D visualization +---------------- + +The following example demonstrates how to visualize imported geometry in 3D. +""" + +# %% +# Import the necessary libraries +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +from ansys.mechanical.core import App +from ansys.mechanical.core.examples import delete_downloads, download_file + +# %% +# Initialize the embedded application +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +app = App(globals=globals()) +print(app) + +# %% +# Download and import the geometry file +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# %% +# Download the geometry file +geometry_path = download_file("Valve.pmdb", "pymechanical", "embedding") + +# %% +# Define the model and import the geometry file +model = app.Model + +geometry_import = model.GeometryImportGroup.AddGeometryImport() +geometry_import.Import(geometry_path) + +# %% +# Visualize the model in 3D +# ~~~~~~~~~~~~~~~~~~~~~~~~~ + +app.plot() + +# %% +# .. note:: +# This visualization is currently available only for geometry and on version 24R2 or later + +# %% +# Clean up the files and app +# ~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# Delete the downloaded files +delete_downloads() + +# Close the app +app.close() diff --git a/examples/00_tips/tips_02.py b/examples/00_tips/tips_02.py new file mode 100644 index 000000000..1b66d47d8 --- /dev/null +++ b/examples/00_tips/tips_02.py @@ -0,0 +1,142 @@ +# Copyright (C) 2022 - 2025 ANSYS, Inc. and/or its affiliates. +# SPDX-License-Identifier: MIT +# +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +""".. _ref_tips_02: + +Export image +------------ + +The following example demonstrates how to export an image of the imported geometry +and display it using matplotlib. +""" + +# %% +# Import the necessary libraries +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +from pathlib import Path + +from ansys.mechanical.core import App +from ansys.mechanical.core.examples import delete_downloads, download_file + +# %% +# Initialize the embedded application +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# Create an instance of the App class +app = App() + +# Update the global variables +app.update_globals(globals()) + +# Print the app to ensure it is working +print(app) + +# %% +# Download and import the geometry file +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# %% +# Download the geometry file +geometry_path = download_file("Valve.pmdb", "pymechanical", "embedding") + +# %% +# Import the geometry file + +geometry_import = Model.GeometryImportGroup.AddGeometryImport() +geometry_import.Import(geometry_path) + +# %% +# Configure graphics for image export +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# Set the orientation of the camera +ExtAPI.Graphics.Camera.SetSpecificViewOrientation(ViewOrientationType.Iso) + +# Set the image export format +image_export_format = GraphicsImageExportFormat.PNG + +# Configure the export settings for the image +settings_720p = Ansys.Mechanical.Graphics.GraphicsImageExportSettings() +settings_720p.Resolution = GraphicsResolutionType.EnhancedResolution +settings_720p.Background = GraphicsBackgroundType.White +settings_720p.Width = 1280 +settings_720p.Height = 720 +settings_720p.CurrentGraphicsDisplay = False + +# Rotate the geometry on the Y-axis +Graphics.Camera.Rotate(180, CameraAxisType.ScreenY) + +# %% +# Create a function to display the image +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +from matplotlib import image as mpimg +from matplotlib import pyplot as plt + +# Directory to save the image +output_path = Path.cwd() / "out" + + +def display_image(image_name) -> None: + """Display the image using matplotlib. + + Parameters + ---------- + image_name : str + The name of the image file to display. + """ + # Create the full path to the image + image_path = output_path / image_name + + # Plot the figure and display the image + plt.figure(figsize=(16, 9)) + plt.imshow(mpimg.imread(str(image_path))) + plt.xticks([]) + plt.yticks([]) + plt.axis("off") + plt.show() + + +# %% +# Export and display the image +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# Fit the geometry in the viewing area +Graphics.Camera.SetFit() + +# Export the image +geometry_image = output_path / "geometry.png" +Graphics.ExportImage(str(geometry_image), image_export_format, settings_720p) + +# Display the image +display_image(geometry_image.name) + +# %% +# Clean up the downloaded files and app +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# Delete the downloaded files +delete_downloads() + +# Close the app +app.close() diff --git a/examples/00_tips/tips_03.py b/examples/00_tips/tips_03.py new file mode 100644 index 000000000..d896faa3c --- /dev/null +++ b/examples/00_tips/tips_03.py @@ -0,0 +1,78 @@ +# Copyright (C) 2022 - 2025 ANSYS, Inc. and/or its affiliates. +# SPDX-License-Identifier: MIT +# +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +""".. _ref_tips_03: + +Project tree +------------ + +The following example demonstrates how to print the heirarchial Mechanical project structure. +""" + +# %% +# Import the necessary libraries +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +from ansys.mechanical.core import App +from ansys.mechanical.core.examples import delete_downloads, download_file + +# %% +# Initialize the embedded application +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +app = App(globals=globals()) +print(app) + +# %% +# Download the mechdb file +# ~~~~~~~~~~~~~~~~~~~~~~~~ + +mechdb_path = download_file("graphics_test.mechdb", "pymechanical", "test_files") + +# %% +# Load the mechdb file inside Mechanical + +app.open(mechdb_path) + +# %% +# Display the project tree +# ~~~~~~~~~~~~~~~~~~~~~~~~ + +app.print_tree() + +# %% +# Display the tree only under the first analysis +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +first_analysis = app.Model.Analyses[0] +app.print_tree(first_analysis) + + +# %% +# Clean up the downloaded files and app +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# Delete the downloaded files +delete_downloads() + +# Close the app +app.close() diff --git a/examples/embedding_n_remote/README.txt b/examples/embedding_n_remote/README.txt deleted file mode 100644 index c7653224b..000000000 --- a/examples/embedding_n_remote/README.txt +++ /dev/null @@ -1,5 +0,0 @@ -Embedding and Remote Session Example -==================================== - -This code, which uses the same example, first demonstrates how to use -an embedding instance and then demonstrates how to use a remote session. \ No newline at end of file diff --git a/examples/embedding_n_remote/embedding_remote.py b/examples/embedding_n_remote/embedding_remote.py deleted file mode 100644 index 50a3f82a9..000000000 --- a/examples/embedding_n_remote/embedding_remote.py +++ /dev/null @@ -1,304 +0,0 @@ -# Copyright (C) 2022 - 2025 ANSYS, Inc. and/or its affiliates. -# SPDX-License-Identifier: MIT -# -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -""".. _ref_embedding_remote: - -Remote & Embedding Example --------------------------- -This code, which uses the same example, first demonstrates how to use -a remote session and then demonstrates how to use an embedding instance. - -""" - -############################################################################### -# -------------- -# Remote Session -# -------------- - - -############################################################################### -# Download required files -# ~~~~~~~~~~~~~~~~~~~~~~~ -# Download the required files. Print the file paths for the geometry file and -# script file. - -import os - -from ansys.mechanical.core import launch_mechanical -from ansys.mechanical.core.examples import download_file - -geometry_path = download_file("Valve.pmdb", "pymechanical", "embedding") -print(f"Downloaded the geometry file to: {geometry_path}") - -script_file_path = download_file("remote_script.py", "pymechanical", "embedding") -print(f"Downloaded the script file to: {script_file_path}") - - -############################################################################### -# -# 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. - -import os - -from ansys.mechanical.core import launch_mechanical - -# Launch mechanical -mechanical = launch_mechanical(batch=True, loglevel="DEBUG") -print(mechanical) - - -############################################################################### -# Initialize variable for workflow -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# Set the ``part_file_path`` variable on the server for later use. -# Make this variable compatible for Windows, Linux, and Docker containers. - -project_directory = mechanical.project_directory -print(f"project directory = {project_directory}") - -# Upload the file to the project directory. -mechanical.upload(file_name=geometry_path, file_location_destination=project_directory) - -# Build the path relative to project directory. -base_name = os.path.basename(geometry_path) -combined_path = os.path.join(project_directory, base_name) -part_file_path = combined_path.replace("\\", "\\\\") -mechanical.run_python_script(f"part_file_path='{part_file_path}'") - -# Verify the path -result = mechanical.run_python_script("part_file_path") -print(f"part_file_path on server: {result}") - - -############################################################################### -# Run mechanical automation script -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# Run remote_script.py in the mechanical remote session. - -mechanical.run_python_script_from_file(script_file_path) - - -############################################################################### -# Get list of generated files -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -list_files = mechanical.list_files() -for file in list_files: - print(file) - - -############################################################################### -# Write the file contents to console -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - -def write_file_contents_to_console(path, number_lines=-1): - count = 1 - with open(path, "rt") as file: - for line in file: - if number_lines == -1 or count <= number_lines: - print(line, end="") - count = count + 1 - else: - break - - -############################################################################### -# Download files back to local working directory -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -dest_dir = "download" -dest_dir = os.path.join(os.getcwd(), dest_dir) -for file in list_files: - downloaded = mechanical.download(file, target_dir=dest_dir) - if file.endswith(".out"): - print("contents of ", downloaded, " : ") - write_file_contents_to_console(downloaded[0], number_lines=-1) - - -############################################################################### -# Exit remote session -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# Close the Mechanical instance. - -mechanical.exit() - -############################################################################### -# ----------------- -# Embedded Instance -# ----------------- - - -############################################################################### -# Download the geometry file -# ~~~~~~~~~~~~~~~~~~~~~~~~~~ -# Download Valve.pmdb. - -import os - -import ansys.mechanical.core as mech -from ansys.mechanical.core.examples import download_file - -geometry_path = download_file("Valve.pmdb", "pymechanical", "embedding") -print(f"Downloaded the geometry file to: {geometry_path}") - - -############################################################################### -# Embed Mechanical and set global variables -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# Find the mechanical installation path & version. -# Open an embedded instance of Mechanical and set global variables. - -app = mech.App(globals=globals()) -print(app) - - -############################################################################### -# Add Static Analysis -# ~~~~~~~~~~~~~~~~~~~ -# Add static analysis to the Model. - -analysis = Model.AddStaticStructuralAnalysis() - - -############################################################################### -# Import geometry -# ~~~~~~~~~~~~~~~ - -geometry_file = geometry_path -geometry_import = Model.GeometryImportGroup.AddGeometryImport() -geometry_import_format = Ansys.Mechanical.DataModel.Enums.GeometryImportPreference.Format.Automatic -geometry_import_preferences = Ansys.ACT.Mechanical.Utilities.GeometryImportPreferences() -geometry_import_preferences.ProcessNamedSelections = True -geometry_import.Import(geometry_file, geometry_import_format, geometry_import_preferences) - - -############################################################################### -# Assign material -# ~~~~~~~~~~~~~~~ - -matAssignment = Model.Materials.AddMaterialAssignment() -tempSel = ExtAPI.SelectionManager.CreateSelectionInfo( - Ansys.ACT.Interfaces.Common.SelectionTypeEnum.GeometryEntities -) -bodies = [ - body - for body in ExtAPI.DataModel.Project.Model.Geometry.GetChildren( - Ansys.Mechanical.DataModel.Enums.DataModelObjectCategory.Body, True - ) -] -geobodies = [body.GetGeoBody() for body in bodies] -ids = System.Collections.Generic.List[System.Int32]() -[ids.Add(item.Id) for item in geobodies] -tempSel.Ids = ids -matAssignment.Location = tempSel -matAssignment.Material = "Structural Steel" - - -############################################################################### -# Define mesh settings -# ~~~~~~~~~~~~~~~~~~~~ - -mesh = Model.Mesh -mesh.ElementSize = Quantity("25 [mm]") -mesh.GenerateMesh() - - -############################################################################### -# Define boundary conditions -# ~~~~~~~~~~~~~~~~~~~~~~~~~~ - -fixedSupport = analysis.AddFixedSupport() -fixedSupport.Location = ExtAPI.DataModel.GetObjectsByName("NSFixedSupportFaces")[0] - -frictionlessSupport = analysis.AddFrictionlessSupport() -frictionlessSupport.Location = ExtAPI.DataModel.GetObjectsByName("NSFrictionlessSupportFaces")[0] - -pressure = analysis.AddPressure() -pressure.Location = ExtAPI.DataModel.GetObjectsByName("NSInsideFaces")[0] - -inputs_quantities = [Quantity("0 [s]"), Quantity("1 [s]")] -output_quantities = [Quantity("0 [Pa]"), Quantity("15 [MPa]")] - -inputs_quantities_2 = System.Collections.Generic.List[Ansys.Core.Units.Quantity]() -[inputs_quantities_2.Add(item) for item in inputs_quantities] - -output_quantities_2 = System.Collections.Generic.List[Ansys.Core.Units.Quantity]() -[output_quantities_2.Add(item) for item in output_quantities] - -pressure.Magnitude.Inputs[0].DiscreteValues = inputs_quantities_2 -pressure.Magnitude.Output.DiscreteValues = output_quantities_2 - - -############################################################################### -# Solve model -# ~~~~~~~~~~~ - -Model.Solve(True) -solution = analysis.Solution - -assert solution.Status == SolutionStatusType.Done - -############################################################################### -# Add results -# ~~~~~~~~~~~ - -solution.AddTotalDeformation() -solution.AddEquivalentStress() -solution.EvaluateAllResults() - - -############################################################################### -# Save model -# ~~~~~~~~~~ - -project_directory = ExtAPI.DataModel.Project.ProjectDirectory -print(f"project directory = {project_directory}") -ExtAPI.DataModel.Project.SaveAs(os.path.join(project_directory, "file.mechdb")) - - -############################################################################### -# Export result values to a text file -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -fileExtension = r".txt" -results = solution.GetChildren( - Ansys.Mechanical.DataModel.Enums.DataModelObjectCategory.Result, True -) - -for result in results: - fileName = str(result.Name) - print(f"filename: {fileName}") - path = os.path.join(project_directory, fileName + fileExtension) - print(path) - result.ExportToTextFile(f"{path}") - print("Exported Text file Contents", path) - try: - write_file_contents_to_console(path, number_lines=20) - except: - print(os.listdir(project_directory)) - -app.close() diff --git a/pyproject.toml b/pyproject.toml index 4ab7719ca..0bebf0611 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -53,7 +53,7 @@ tests = [ "pytest==8.4.0", "pytest-cov==6.2.1", "pytest-print==1.1.0", - "psutil==7.0.0" + "psutil==7.0.0", ] doc = [ "sphinx==8.2.3", @@ -81,6 +81,8 @@ doc = [ "sphinx-notfound-page==1.1.0", "sphinxcontrib-websupport==2.0.0", "sphinxemoji==0.3.1", + "pyvista[jupyter]>=0.39.1", + "ipyvtklink==0.2.3", ] # Viz option will be removed in future versions viz = [ diff --git a/src/ansys/mechanical/core/embedding/initializer.py b/src/ansys/mechanical/core/embedding/initializer.py index 983e7a743..78a75da37 100644 --- a/src/ansys/mechanical/core/embedding/initializer.py +++ b/src/ansys/mechanical/core/embedding/initializer.py @@ -198,9 +198,9 @@ def __check_for_mechanical_env(): """Embedding in linux platform must use mechanical-env.""" if platform.system() == "Linux" and os.environ.get("PYMECHANICAL_EMBEDDING") != "TRUE": raise Exception( - "On linux, embedding an instance of the Mechanical process using" + "On Linux, embedding an instance of the Mechanical process using " "the App class requires running python inside of a Mechanical environment." - "Use the `mechanical-env` script to do this. For more information, refer to:" + "Use the `mechanical-env` script to do this. For more information, refer to: " "https://mechanical.docs.pyansys.com/version/stable/" "getting_started/running_mechanical.html#embed-a-mechanical-instance" ) diff --git a/src/ansys/mechanical/core/embedding/rpc/__init__.py b/src/ansys/mechanical/core/embedding/rpc/__init__.py index 2fb3584f1..986239346 100644 --- a/src/ansys/mechanical/core/embedding/rpc/__init__.py +++ b/src/ansys/mechanical/core/embedding/rpc/__init__.py @@ -23,10 +23,7 @@ """RPC and Mechanical service implementation.""" from .client import Client from .default_server import DefaultServiceMethods, MechanicalDefaultServer -from .server import ( - MechanicalEmbeddedServer, - MechanicalService, -) +from .server import MechanicalEmbeddedServer, MechanicalService from .utils import get_remote_methods, remote_method # todo - combine Server and MechanicalService