### Install Ansys Visualization Interface Tool from GitHub Source: https://github.com/ansys/ansys-tools-visualization-interface/blob/main/doc/source/getting_started/index.rst Installs the Ansys Visualization Interface Tool from its GitHub repository. This involves cloning the repository, navigating into the directory, and then installing using pip. This method is useful for developers or when needing the latest unreleased version. ```bash git clone https://github.com/ansys/ansys-tools-visualization-interface cd ansys-tools-visualization-interface pip install . ``` -------------------------------- ### Install Test Dependencies for Visualization Interface Tool Source: https://github.com/ansys/ansys-tools-visualization-interface/blob/main/doc/source/contributing.rst Installs the necessary dependencies to run tests for the Visualization Interface Tool. This command should be run after cloning the repository and installing in developer mode. ```bash pip install -e .[tests] ``` -------------------------------- ### Install Ansys Visualization Interface Tool using pip Source: https://github.com/ansys/ansys-tools-visualization-interface/blob/main/doc/source/getting_started/index.rst Installs the Ansys Visualization Interface Tool using pip. This is the standard method for adding the tool to your Python environment. No specific inputs or outputs are generated by this command itself, but it makes the tool available for use. ```bash pip install ansys-tools-visualization-interface ``` -------------------------------- ### Install Documentation Dependencies for Visualization Interface Tool Source: https://github.com/ansys/ansys-tools-visualization-interface/blob/main/doc/source/contributing.rst Installs the required packages to build the documentation for the Visualization Interface Tool. This should be done before attempting to build the documentation locally. ```bash pip install -e .[doc] ``` -------------------------------- ### Build Documentation for Ansys Tools Visualization Interface Source: https://github.com/ansys/ansys-tools-visualization-interface/blob/main/CONTRIBUTING.md Installs documentation dependencies and builds the HTML documentation. This process involves installing the required packages and then using Make (or a batch script on Windows) to generate the documentation files. ```bash pip install -e .[doc] cd doc # On linux make html # On windows ./make.bat html ``` -------------------------------- ### Install Test Dependencies and Run Tests Source: https://github.com/ansys/ansys-tools-visualization-interface/blob/main/CONTRIBUTING.md Installs the necessary dependencies for running tests and then executes the test suite. This ensures that all code changes are validated before merging. ```bash pip install -e .[tests] pytest ``` -------------------------------- ### Set Up and Run Code Style Checks with Pre-commit Source: https://github.com/ansys/ansys-tools-visualization-interface/blob/main/CONTRIBUTING.md Installs and runs pre-commit to ensure code adheres to PEP8 standards. This involves installing pre-commit, running all files through the checks, or installing it as a git hook for automatic checks before commits. ```bash pip install pre-commit pre-commit run --all-files ``` ```bash pre-commit install ``` -------------------------------- ### Build HTML Documentation (Windows) Source: https://github.com/ansys/ansys-tools-visualization-interface/blob/main/doc/source/contributing.rst Builds the HTML documentation for the Visualization Interface Tool on Windows systems. This command is run from the 'docs' directory after installing documentation dependencies. ```bash ./make.bat html ``` -------------------------------- ### Build HTML Documentation (Linux/macOS) Source: https://github.com/ansys/ansys-tools-visualization-interface/blob/main/doc/source/contributing.rst Builds the HTML documentation for the Visualization Interface Tool on Linux or macOS systems. This command is run from the 'docs' directory after installing documentation dependencies. ```bash make html ``` -------------------------------- ### Install and Run Pre-commit for Code Style Checks Source: https://github.com/ansys/ansys-tools-visualization-interface/blob/main/doc/source/contributing.rst Installs pre-commit and runs all configured code style checks on the entire repository to ensure adherence to PEP8 standards. This is crucial for maintaining code quality. ```bash pip install pre-commit pre-commit run --all-files ``` -------------------------------- ### Clone and Install Ansys Tools Visualization Interface Source: https://github.com/ansys/ansys-tools-visualization-interface/blob/main/CONTRIBUTING.md Clones the Ansys Tools Visualization Interface repository and installs it in development mode. This involves cloning the git repository, navigating into the directory, upgrading pip, and then performing a development installation. ```bash git clone https://github.com/ansys/ansys-tools-visualization-interface/ cd ansys-tools-visualization-interface python -m pip install --upgrade pip pip install -e . ``` -------------------------------- ### Use PyVista Qt Backend with Ansys Tools Visualization Interface Source: https://github.com/ansys/ansys-tools-visualization-interface/blob/main/doc/source/user_guide/migration.rst Demonstrates how to set up and use the PyVista Qt backend with the Ansys Tools Visualization Interface plotter. This involves initializing the PyVista backend with Qt support and then creating the plotter. It also shows how to enable widgets and display the scene, with an option to integrate into PyQt/PySide applications. ```python cube = pv.Cube() pv_backend = PyVistaBackend(use_qt=True, show_qt=True) pl = Plotter(backend=pv_backend) pl.plot(cube) pl.backend.enable_widgets() pv_backend.scene.show() ``` -------------------------------- ### Visualize PyVista Mesh using Visualization Interface Tool Source: https://github.com/ansys/ansys-tools-visualization-interface/blob/main/doc/source/getting_started/index.rst Demonstrates how to use the Visualization Interface Tool to plot a mesh object that is compatible with PyVista. It initializes a Plotter object and then calls its plot and show methods to display the mesh. Assumes `my_custom_object.get_mesh()` returns a PyVista-compatible mesh. ```python from ansys.tools.visualization_interface import Plotter my_mesh = my_custom_object.get_mesh() # Create a Visualization Interface Tool object pl = Plotter() pl.plot(my_mesh) # Plot the result pl.show() ``` -------------------------------- ### Install Pre-commit Hook for Automatic Style Checks Source: https://github.com/ansys/ansys-tools-visualization-interface/blob/main/doc/source/contributing.rst Installs pre-commit as a Git hook, which automatically runs style checks before each commit. This prevents committing code that fails style standards. ```bash pre-commit install ``` -------------------------------- ### Install Visualization Interface Tool in Developer Mode Source: https://github.com/ansys/ansys-tools-visualization-interface/blob/main/doc/source/contributing.rst Clones the repository and installs the Visualization Interface Tool in editable mode, allowing for source code modifications. This process requires Git and Python with pip. ```bash git clone https://github.com/ansys/ansys-tools-visualization-interface cd ansys-tools-visualization-interface python -m pip install --upgrade pip pip install -e . ``` -------------------------------- ### Migrate PyVista Documentation Configuration Source: https://github.com/ansys/ansys-tools-visualization-interface/blob/main/doc/source/user_guide/migration.rst Provides steps to migrate documentation configuration from PyVista to the Ansys Tools Visualization Interface. This includes setting environment variables, configuring Sphinx Gallery with DynamicScraper, and adding the PyVista viewer directive to extensions. It also ensures notebook cells are executed. ```python import os os.environ["PYANSYS_VISUALIZER_DOC_MODE"] = "true" os.environ["PYANSYS_VISUALIZER_HTML_BACKEND"] = "true" ``` ```python from pyvista.plotting.utilities.sphinx_gallery import DynamicScraper sphinx_gallery_conf = { "image_scrapers": (DynamicScraper()) } ``` ```python extensions = ["pyvista.ext.viewer_directive"] ``` ```python nbsphinx_execute = "always" ``` -------------------------------- ### Visualize PyAnsys Object Mesh using Visualization Interface Tool Source: https://github.com/ansys/ansys-tools-visualization-interface/blob/main/doc/source/getting_started/index.rst Shows how to visualize a mesh associated with a PyAnsys object using the Visualization Interface Tool. It creates a `MeshObjectPlot` instance from the custom object and its mesh, then plots this object using the Plotter. Assumes `MyObject` and its `get_mesh` method are defined. ```python from ansys.tools.visualization_interface import Plotter, MeshObjectPlot my_custom_object = MyObject() my_mesh = my_custom_object.get_mesh() mesh_object = MeshObjectPlot(my_custom_object, my_mesh) # Create a Visualization Interface Tool object pl = Plotter() pl.plot(mesh_object) # Plot the result pl.show() ``` -------------------------------- ### Customize Ansys Tools Visualization Interface Plotter Backend with PyVistaBackend Source: https://github.com/ansys/ansys-tools-visualization-interface/blob/main/doc/source/user_guide/migration.rst Illustrates how to customize the Ansys Tools Visualization Interface plotter's backend, specifically enabling picking functionality using `PyVistaBackend`. This allows for more interactive visualization. ```python from ansys.tools.visualization_interface import Plotter from ansys.tools.visualization_interface.backends import PyVistaBackend backend = PyVistaBackend(allow_picking=True) # Create a plotter pl = Plotter(backend=backend) # Add the MeshObjectPlot instance to the plotter pl.plot(mesh_object_plot) # Show the plotter pl.show() ``` -------------------------------- ### Plot PyVista Mesh with Default Plotter Source: https://github.com/ansys/ansys-tools-visualization-interface/blob/main/doc/source/user_guide/index.rst Demonstrates how to use the default plotter to visualize a simple PyVista mesh. This requires the PyVista library and the Visualization Interface Tool. ```python ## Usage example with pyvista meshes ## import pyvista as pv from ansys.tools.visualization_interface import Plotter # Create a pyvista mesh mesh = pv.Cube() # Create a plotter pl = Plotter() # Add the mesh to the plotter pl.plot(mesh) # Show the plotter pl.show() ``` -------------------------------- ### Run Tests for Visualization Interface Tool Source: https://github.com/ansys/ansys-tools-visualization-interface/blob/main/doc/source/contributing.rst Executes the test suite for the Visualization Interface Tool using pytest. Ensure all test dependencies are installed prior to running this command. ```bash pytest ``` -------------------------------- ### Migrate Plotly Documentation Configuration Source: https://github.com/ansys/ansys-tools-visualization-interface/blob/main/doc/source/user_guide/migration.rst Details the configuration steps for migrating Plotly documentation to the Ansys Tools Visualization Interface. This involves setting an environment variable, configuring Plotly's default renderer for Sphinx Gallery, and adding both DynamicScraper and Plotly's scraper to the Sphinx Gallery configuration. It emphasizes that `pl.show()` must be the last line in a cell. ```python import os os.environ["PYANSYS_VISUALIZER_DOC_MODE"] = "true" ``` ```python import plotly.io as pio pio.renderers.default = "sphinx_gallery" ``` ```python from pyvista.plotting.utilities.sphinx_gallery import DynamicScraper from plotly.io._sg_scraper import plotly_sg_scraper sphinx_gallery_conf = { "image_scrapers": (DynamicScraper(), "matplotlib", plotly_sg_scraper) } ``` -------------------------------- ### Replace PyVista Plotter with Ansys Tools Visualization Interface Plotter Source: https://github.com/ansys/ansys-tools-visualization-interface/blob/main/doc/source/user_guide/migration.rst Demonstrates replacing PyVista's plotter code with the Ansys Tools Visualization Interface plotter for simple mesh visualization. This migration is straightforward for basic plotting needs. ```python import pyvista as pv # Create a PyVista mesh mesh = pv.Cube() # Create a plotter pl = pv.Plotter() # Add the mesh to the plotter pl.add_mesh(mesh) # Show the plotter pl.show() ``` ```python import pyvista as pv from ansys.tools.visualization_interface import Plotter # Create a PyVista mesh mesh = pv.Cube() # Create a plotter pl = Plotter() # Add the mesh to the plotter pl.plot(mesh) # Show the plotter pl.show() ``` -------------------------------- ### Programmatically Control Animation Playback Source: https://context7.com/ansys/ansys-tools-visualization-interface/llms.txt Provides examples of controlling animation playback programmatically. This includes methods to play, pause, stop, step forward/backward, and seek to a specific frame. It also shows how to access animation properties like current frame, total frames, FPS, and state. ```python import pyvista as pv from ansys.tools.visualization_interface import Plotter # Create sample frames frames = [pv.Sphere(radius=0.5 + i * 0.1) for i in range(10)] plotter = Plotter() animation = plotter.animate(frames, fps=10, loop=False) # Playback controls animation.play() # Start playback animation.pause() # Pause playback animation.stop() # Stop and reset to frame 0 animation.step_forward() # Advance one frame animation.step_backward() # Go back one frame animation.seek(5) # Jump to frame 5 # Properties print(f"Current frame: {animation.current_frame}") print(f"Total frames: {animation.total_frames}") print(f"FPS: {animation.fps}") print(f"State: {animation.state}" ) # STOPPED, PLAYING, or PAUSED ``` -------------------------------- ### Convert Custom Meshes for Ansys Tools Visualization Interface Plotter Source: https://github.com/ansys/ansys-tools-visualization-interface/blob/main/doc/source/user_guide/migration.rst Shows how to adapt custom objects for visualization with the Ansys Tools Visualization Interface plotter. The custom object must provide a `get_mesh` method and a `name` or `id` attribute. ```python class CustomObject: def __init__(self): self.name = "CustomObject" self.mesh = pv.Cube(center=(1, 1, 0)) def get_mesh(self): return self.mesh def name(self): return self.name ``` ```python from ansys.tools.visualization_interface import MeshObjectPlot custom_object = CustomObject() mesh_object_plot = MeshObjectPlot( custom_object=custom_object, mesh=custom_object.get_mesh(), ) ``` -------------------------------- ### Utilize Color Utilities for Consistent Visualization Styling (Python) Source: https://context7.com/ansys/ansys-tools-visualization-interface/llms.txt Shows how to use the `Color` utility class from `ansys.tools.visualization_interface.utils.color` to access predefined color constants. These constants can be used directly when plotting objects to ensure consistent styling across visualizations. Examples include default mesh color, picked object color, and edge colors. ```python from ansys.tools.visualization_interface.utils.color import Color # Available color presets print(Color.DEFAULT.value) # "#D6F7D1" - Default mesh color print(Color.PICKED.value) # "#BB6EEE" - Picked object color print(Color.EDGE.value) # "#000000" - Edge color print(Color.PICKED_EDGE.value) # "#9C9C9C" - Picked edge color # Use in plotting import pyvista as pv from ansys.tools.visualization_interface import Plotter pl = Plotter() pl.plot(pv.Cube(), color=Color.DEFAULT.value) pl.show() ``` -------------------------------- ### Plot PyAnsys Custom Object with Default Plotter Source: https://github.com/ansys/ansys-tools-visualization-interface/blob/main/doc/source/user_guide/index.rst Illustrates visualizing PyAnsys custom objects using the default plotter. The custom object must provide a method to return a PyVista mesh and expose a 'name' or 'id' attribute. This uses MeshObjectPlot to bridge custom objects and PyVista meshes. ```python ## Usage example with PyAnsys custom objects ## from ansys.tools.visualization_interface import Plotter from ansys.tools.visualization_interface import MeshObjectPlot # Create a custom object for this example class CustomObject: def __init__(self): self.name = "CustomObject" self.mesh = pv.Cube() def get_mesh(self): return self.mesh def name(self): return self.name custom_object = CustomObject() # Create a MeshObjectPlot instance mesh_object = MeshObjectPlot(custom_object, custom_object.get_mesh()) # Create a plotter pl = Plotter() # Add the MeshObjectPlot instance to the plotter pl.plot(mesh_object) # Show the plotter pl.show() ``` -------------------------------- ### Integrate Qt Backend with PyVista Source: https://context7.com/ansys/ansys-tools-visualization-interface/llms.txt This snippet shows how to integrate the PyVistaQt backend for use with Qt-based applications. It initializes PyVistaBackend with `use_qt=True` and `show_qt=True` to display the Qt window. The `backend.close()` method is used to programmatically close the Qt window. ```python import pyvista as pv from ansys.tools.visualization_interface import Plotter from ansys.tools.visualization_interface.backends.pyvista import PyVistaBackend # Enable Qt backend (requires pyvistaqt) backend = PyVistaBackend( use_qt=True, show_qt=True # Set False to create hidden window ) pl = Plotter(backend=backend) pl.plot(pv.Sphere()) pl.show() # Close Qt window programmatically backend.close() ``` -------------------------------- ### Clean Documentation Build (Linux/macOS) Source: https://github.com/ansys/ansys-tools-visualization-interface/blob/main/doc/source/contributing.rst Removes previously generated documentation build files on Linux or macOS systems. This is useful for ensuring a clean build. ```bash make clean ``` -------------------------------- ### Clean Documentation Build (Windows) Source: https://github.com/ansys/ansys-tools-visualization-interface/blob/main/doc/source/contributing.rst Removes previously generated documentation build files on Windows systems. This is useful for ensuring a clean build. ```bash ./make.bat clean ``` -------------------------------- ### Basic Plotting with Plotter Class Source: https://context7.com/ansys/ansys-tools-visualization-interface/llms.txt Demonstrates basic plotting using the Plotter class. It initializes a plotter instance and displays a PyVista mesh. Requires the PyVista library. ```python import pyvista as pv from ansys.tools.visualization_interface import Plotter # Create a simple mesh mesh = pv.Cube() # Create a plotter and display pl = Plotter() pl.plot(mesh) pl.show() ``` -------------------------------- ### Export Animations to Video and GIF Formats Source: https://context7.com/ansys/ansys-tools-visualization-interface/llms.txt Demonstrates how to export created animations to video files (e.g., MP4) or animated GIFs. This involves generating frame data, creating the animation object, and then using the `save` method with specified filenames and quality/framerate settings. ```python import numpy as np import pyvista as pv from ansys.tools.visualization_interface import Plotter # Create frame data sphere = pv.Sphere() frames = [] for i in range(20): mesh = sphere.copy() mesh["data"] = np.random.rand(mesh.n_points) * (i + 1) * 0.1 frames.append(mesh) # Create animation plotter = Plotter() animation = plotter.animate(frames, fps=30) # Export to video file animation.save("simulation_output.mp4", quality=8) # Or export as GIF animation.save("simulation_output.gif", framerate=15) ``` -------------------------------- ### Enable Trame Web Visualization with PyVista Backend Source: https://context7.com/ansys/ansys-tools-visualization-interface/llms.txt This snippet demonstrates how to enable web-based visualization using Trame with the PyVista backend. It initializes the PyVistaBackend with `use_trame=True` and then uses the Plotter to display a PyVista sphere, which opens in a web browser. ```python import pyvista as pv from ansys.tools.visualization_interface import Plotter from ansys.tools.visualization_interface.backends.pyvista import PyVistaBackend # Enable Trame backend backend = PyVistaBackend(use_trame=True) pl = Plotter(backend=backend) pl.plot(pv.Sphere()) pl.show() # Opens in web browser ``` -------------------------------- ### Custom Object Mapping with MeshObjectPlot Source: https://context7.com/ansys/ansys-tools-visualization-interface/llms.txt Illustrates how to map custom objects to their mesh representations using MeshObjectPlot for tracking, picking, and visibility management. Requires PyVista. ```python import pyvista as pv from ansys.tools.visualization_interface import Plotter, MeshObjectPlot # Define a custom object with name and mesh class SimulationResult: def __init__(self, name, center): self.name = name self.mesh = pv.Sphere(center=center) def get_mesh(self): return self.mesh # Create custom objects result1 = SimulationResult("Temperature Field", (0, 0, 0)) result2 = SimulationResult("Pressure Field", (3, 0, 0)) # Wrap in MeshObjectPlot for tracking mesh_object1 = MeshObjectPlot(result1, result1.get_mesh()) mesh_object2 = MeshObjectPlot(result2, result2.get_mesh()) # Plot with full tracking capabilities pl = Plotter() pl.plot(mesh_object1) pl.plot(mesh_object2) pl.show() # Objects can now be picked and tracked by name ``` -------------------------------- ### Create Time Series Animations with Playback Controls Source: https://context7.com/ansys/ansys-tools-visualization-interface/llms.txt Generates animations from time-series simulation data, such as wave propagation. It includes options for setting frames per second (fps), looping, and displaying a scalar bar. The animation can then be shown with interactive playback controls. ```python import numpy as np import pyvista as pv from ansys.tools.visualization_interface import Plotter # Generate animation frames (e.g., wave propagation) def create_wave_mesh(time_step, n_points=50): x = np.linspace(-5, 5, n_points) y = np.linspace(-5, 5, n_points) x, y = np.meshgrid(x, y) t = time_step * 0.2 z = np.sin(np.sqrt(x**2 + y**2) - t) * np.exp(-0.1 * np.sqrt(x**2 + y**2)) mesh = pv.StructuredGrid(x, y, z) mesh["displacement"] = np.abs(z).ravel() return mesh # Create 30 frames frames = [create_wave_mesh(i) for i in range(30)] # Create animation with controls plotter = Plotter() animation = plotter.animate( frames, fps=20, loop=True, scalar_bar_args={"title": "Displacement"} ) # Display with interactive controls animation.show() ``` -------------------------------- ### Interactive Picking with PyVistaBackend Source: https://context7.com/ansys/ansys-tools-visualization-interface/llms.txt Enables interactive picking of objects in the scene using the PyVista backend. Allows users to click on objects to select them and display their names. Requires PyVista. ```python import pyvista as pv from ansys.tools.visualization_interface import Plotter, MeshObjectPlot from ansys.tools.visualization_interface.backends.pyvista import PyVistaBackend # Create custom objects class Component: def __init__(self, name, mesh): self.name = name self.mesh = mesh comp1 = Component("Engine Block", pv.Cube(center=(0, 0, 0))) comp2 = Component("Cylinder Head", pv.Sphere(center=(0, 0, 2))) mesh_obj1 = MeshObjectPlot(comp1, comp1.mesh) mesh_obj2 = MeshObjectPlot(comp2, comp2.mesh) # Enable picking - click to select objects pv_backend = PyVistaBackend( allow_picking=True, # Enable click-to-pick plot_picked_names=True # Show labels on picked objects ) pl = Plotter(backend=pv_backend) pl.plot(mesh_obj1) pl.plot(mesh_obj2) # Returns list of picked objects after window closes picked_objects = pl.show() print(f"Picked: {[obj.name for obj in picked_objects]}") ``` -------------------------------- ### Hover Functionality with PyVistaBackend Source: https://context7.com/ansys/ansys-tools-visualization-interface/llms.txt Configures the PyVista backend to enable hover-based object identification without requiring clicks. This allows for dynamic display of object information as the mouse hovers over them. Requires PyVista. ```python import pyvista as pv from ansys.tools.visualization_interface import Plotter, MeshObjectPlot from ansys.tools.visualization_interface.backends.pyvista import PyVistaBackend # Create mesh objects class Part: def __init__(self, name, mesh): self.name = name self.mesh = mesh parts = [ Part("Rotor", pv.Cylinder(center=(0, 0, 0), radius=0.5)), Part("Stator", pv.Cylinder(center=(0, 0, 2), radius=0.8)), ] # Note: The provided snippet is incomplete for demonstrating hover functionality. # A full example would involve setting allow_hover=True in PyVistaBackend and potentially defining hover text. # Example structure: # pv_backend = PyVistaBackend(allow_hover=True, ...) # pl = Plotter(backend=pv_backend) # ... plot objects ... # pl.show() ``` -------------------------------- ### PlotlyBackend for Screenshot Export Source: https://context7.com/ansys/ansys-tools-visualization-interface/llms.txt Demonstrates exporting Plotly visualizations generated by the Ansys Tools Visualization Interface to static image files (e.g., PNG) or interactive HTML files. This is achieved by calling the `show` method with the `screenshot` argument specifying the desired output file. ```python import pyvista as pv from ansys.tools.visualization_interface import Plotter from ansys.tools.visualization_interface.backends.plotly.plotly_interface import PlotlyBackend pl = Plotter(backend=PlotlyBackend()) pl.plot(pv.Sphere()) pl.plot(pv.Cube(center=(2, 0, 0))) # Export as static image pl.show(screenshot="visualization.png") # Export as interactive HTML pl.show(screenshot="visualization.html") ``` -------------------------------- ### Create Custom Picker for Extended Selection and Highlighting (Python) Source: https://context7.com/ansys/ansys-tools-visualization-interface/llms.txt Defines a custom picker class `HighlightPicker` that extends `AbstractPicker` to provide custom selection and highlighting behavior. It stores original colors, changes picked objects to red, adds labels, and manages hover effects. This picker is then integrated into the `PyVistaBackend`. ```python import pyvista as pv from ansys.tools.visualization_interface import Plotter, MeshObjectPlot from ansys.tools.visualization_interface.backends.pyvista import PyVistaBackend from ansys.tools.visualization_interface.backends.pyvista.picker import AbstractPicker from ansys.tools.visualization_interface.utils.color import Color class HighlightPicker(AbstractPicker): """Custom picker that highlights objects in red.""" def __init__(self, plotter_backend, custom_label="Selected: "): self._plotter_backend = plotter_backend self._custom_label = custom_label self._picked_dict = {} self._origin_colors = {} self._added_labels = [] self._hover_labels = [] def pick_select_object(self, custom_object, pt): # Store original color and change to red self._origin_colors[custom_object] = custom_object.actor.prop.color custom_object.actor.prop.color = "red" # Add custom label label = self._plotter_backend.pv_interface.scene.add_point_labels( [pt], [f"{self._custom_label}{custom_object.name}"], always_visible=True, point_size=0, show_points=False ) self._added_labels.append(label) self._picked_dict[custom_object.name] = custom_object def pick_unselect_object(self, custom_object): if custom_object in self._origin_colors: custom_object.actor.prop.color = self._origin_colors[custom_object] if custom_object.name in self._picked_dict: self._picked_dict.pop(custom_object.name) for label in self._added_labels: self._plotter_backend._pl.scene.remove_actor(label) self._added_labels.clear() def hover_select_object(self, custom_object, actor): for label in self._hover_labels: self._plotter_backend._pl.scene.remove_actor(label) label = self._plotter_backend._pl.scene.add_point_labels( [actor.GetCenter()], [custom_object.name], always_visible=True, point_size=0, show_points=False ) self._hover_labels.append(label) def hover_unselect_object(self): for label in self._hover_labels: self._plotter_backend._pl.scene.remove_actor(label) @property def picked_dict(self): return self._picked_dict # Use custom picker backend = PyVistaBackend( allow_picking=True, custom_picker=HighlightPicker, custom_picker_kwargs={"custom_label": "Component: "} ) class Part: def __init__(self, name, mesh): self.name = name self.mesh = mesh part = Part("Bracket", pv.Cube()) mesh_obj = MeshObjectPlot(part, part.mesh) pl = Plotter(backend=backend) pl.plot(mesh_obj) pl.show() ``` -------------------------------- ### Create Hierarchical MeshObjectPlot for Parent-Child Relationships (Python) Source: https://context7.com/ansys/ansys-tools-visualization-interface/llms.txt Demonstrates how to create and manage hierarchical structures for complex assemblies using `MeshObjectPlot`. It shows how to define parent-child relationships and control the visibility of components within the hierarchy. Children can have independent visibility settings, but their visibility in the tree is affected by their parent's visibility. ```python import pyvista as pv from ansys.tools.visualization_interface import Plotter, MeshObjectPlot # Create assembly hierarchy class Assembly: def __init__(self, name): self.name = name class Component: def __init__(self, name, mesh): self.name = name self.mesh = mesh # Create parent assembly engine = Assembly("Engine Assembly") engine_mesh = pv.Box(bounds=(-1, 1, -1, 1, -1, 1)) engine_obj = MeshObjectPlot(engine, engine_mesh) # Create child components piston = Component("Piston", pv.Cylinder(center=(0, 0, 0), radius=0.3, height=0.5)) valve = Component("Valve", pv.Cone(center=(0.5, 0, 0), radius=0.1, height=0.3)) piston_obj = MeshObjectPlot(piston, piston.mesh) valve_obj = MeshObjectPlot(valve, valve.mesh) # Build hierarchy engine_obj.add_child(piston_obj) engine_obj.add_child(valve_obj) # Plot with children pl = Plotter() pl.plot(engine_obj, plot_children=True) pl.show() # Visibility management engine_obj.visible = False # Hides engine mesh piston_obj.visible = True # Children can have independent visibility print(f"Piston visible in tree: {piston_obj.is_visible_in_tree()}") # False (parent hidden) ``` -------------------------------- ### Mesh Clipping with ClipPlane Source: https://context7.com/ansys/ansys-tools-visualization-interface/llms.txt Demonstrates clipping a mesh using a ClipPlane object. The plane is defined by its normal and origin vectors, allowing visualization of internal structures. Requires PyVista. ```python import pyvista as pv from ansys.tools.visualization_interface import Plotter, ClipPlane # Create a mesh to clip mesh = pv.Cylinder() # Define clipping plane (normal, origin) clipping_plane = ClipPlane( normal=(1, 0, 0), # Clip along X-axis origin=(0, 0, 0) # Center of clip ) # Plot with clipping pl = Plotter() pl.plot(mesh, clipping_plane=clipping_plane) pl.show() ``` -------------------------------- ### PlotlyBackend for Web-Based 3D Visualization Source: https://context7.com/ansys/ansys-tools-visualization-interface/llms.txt Utilizes the Plotly backend for creating interactive, web-based 3D visualizations. This allows plotting both PyVista mesh objects and native Plotly objects like Scatter3d. The `Plotter` is initialized with `PlotlyBackend()` and then objects are plotted and displayed in a browser. ```python import pyvista as pv from plotly.graph_objects import Mesh3d, Scatter3d from ansys.tools.visualization_interface import Plotter, MeshObjectPlot from ansys.tools.visualization_interface.backends.plotly.plotly_interface import PlotlyBackend # Create Plotly backend plotter pl = Plotter(backend=PlotlyBackend()) # Plot PyVista meshes sphere = pv.Sphere(center=(0, 0, 0)) cube = pv.Cube(center=(2, 0, 0)) pl.plot(sphere) pl.plot(cube) # Plot PyVista MultiBlock multi_block = pv.MultiBlock() multi_block.append(pv.Cone(center=(0, 2, 0))) multi_block.append(pv.Arrow(start=(0, 2, 0), direction=(1, 0, 0))) pl.plot(multi_block) # Plot native Plotly objects scatter = Scatter3d( x=[0, 1, 2], y=[0, 1, 0], z=[0, 0, 1], mode='markers', marker=dict(size=10, color='red') ) pl.plot(scatter, name="Data Points") # Display in browser pl.show() ``` -------------------------------- ### Plotting Multiple Objects with Plotter Source: https://context7.com/ansys/ansys-tools-visualization-interface/llms.txt Shows how to plot multiple meshes in a single scene using the Plotter class. Meshes can be added as a list or through multiple plot calls. Requires PyVista. ```python import pyvista as pv from ansys.tools.visualization_interface import Plotter # Create multiple meshes mesh1 = pv.Cube() mesh2 = pv.Sphere(center=(2, 0, 0)) mesh3 = pv.Cylinder(center=(0, 2, 0)) # Create plotter and add meshes pl = Plotter() # Method 1: Plot a list pl.plot([mesh1, mesh2]) # Method 2: Multiple plot calls pl.plot(mesh3) pl.show() ``` -------------------------------- ### Enable Hover Mode for Object Identification Source: https://context7.com/ansys/ansys-tools-visualization-interface/llms.txt Enables hover mode in the visualization interface, allowing users to see object names when hovering over them. This requires initializing the Plotter with a PyVistaBackend that allows hovering. ```python from ansys.tools.visualization_interface import Plotter from ansys.tools.visualization_interface.backends.pyvista import PyVistaBackend # Enable hover mode pv_backend = PyVistaBackend(allow_hovering=True) pl = Plotter(backend=pv_backend) for part in parts: mesh_obj = MeshObjectPlot(part, part.mesh) pl.plot(mesh_obj) pl.show() # Hover over objects to see their names ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.