.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/02-convert-types.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_02-convert-types.py: .. _ref_convert_vtk_usd_example: ============================== Converting VTK to USD and back ============================== This example shows how to convert a VTK file to USD and then back to VTK. .. GENERATED FROM PYTHON SOURCE LINES 31-58 .. code-block:: Python # Import necessary modules from ansys.tools.usdviewer.vtk_converter import VTKConverter from ansys.tools.usdviewer.viewer import USDViewer from pxr import Usd import pyvista # Read a simple VTK file sphere = pyvista.read("sphere.vtk") # Create a new USD stage stage = Usd.Stage.CreateNew("sphere.usda") # Convert VTK to USD and add to stage stage = VTKConverter.convert_vtk_file_to_usd("sphere.vtk", stage) # View the USD file in the USD Viewer viewer = USDViewer(title="USD Viewer", size=(800, 800)) viewer.load_usd("sphere.usda") viewer.show() # Convert USD back to VTK vtk_pd = VTKConverter.convert_usd_to_vtk(stage) # Visualize the converted VTK data using PyVista plotter = pyvista.Plotter() plotter.add_mesh(vtk_pd, color="lightblue", show_edges=True) plotter.show() .. _sphx_glr_download_examples_02-convert-types.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 02-convert-types.ipynb <02-convert-types.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 02-convert-types.py <02-convert-types.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 02-convert-types.zip <02-convert-types.zip>`