Preparing Ansys Mechanical Results for SimAI Pro with Automated VTU Conversion

Exporting Ansys Mechanical Results for SimAI Pro

SimAI Pro is an exciting new product from Ansys that uses generative AI to quickly predict analysis results based on previous simulation data. An important part of that simulation data is a VTP file that contains the geometry and field results from an Ansys simulation. The VTP file format is a geometry file format from VTK that is not generated natively by Ansys Mechanical. One practical path is to export solved Mechanical results to VTU using Mechanical scripting, then convert that VTU file to a surface VTP file for use as SimAI Pro training data.

This post walks through an example, including code syntax, of extracting Mechanical result data with Ansys Data Processing Framework, writing a VTU file from Mechanical, and then performing the required VTU-to-VTP conversion outside Mechanical with PyVista. The end goal is to create reusable surface-result files that can become part of a SimAI Pro training dataset.

Workflow Overview

  1. Locate the result file generated by Mechanical.
  2. Create a DPF data source from the result file.
  3. Create a DPF operator to perform the file conversion.
  4. Create a time scoping for the time steps of interest.
  5. Connect the inputs to the DPF operator.
  6. Evaluate the operator.
  7. Read the VTU file with PyVista, extract the surface mesh, and save it as VTP.

Example Mechanical Results Script for SimAI Pro

The following Mechanical script exports the solved result data to VTU using the migrate_to_vtu DPF operator. This step is intended to run inside Mechanical; however, it could be adapted for use in an external script through PyAnsys. Inside Mechanical, this script can be run from the automation scripting window or as a Python code object in the analysis solution. In that case, it should use an After Post target callback.

A note on connecting inputs to the DPF operator: the migrate_to_vtu operator does not currently expose its API in Mechanical enough to support the

operator.inputs.<pin_name>.Connect

syntax. For that reason, the script uses a lower-level method that connects inputs by pin number. This may change in future releases, but at the time of writing, the following script is the recommended way to manipulate this operator from within Mechanical. The user is directed to the Ansys documentation for this operator for more information.

import Ans.DataProcessing as dpf
import mech_dpf
import os
#get the results file path
analysis = solution.Parent
rst_path = analysis.ResultFileName 

model = dpf.Model(rst_path)

#setup output directory, in this case a sub-folder of the project directory
user_dir = ExtAPI.DataModel.Project.ProjectDirectory
out_dir = os.path.join(user_dir, "vtu_export")

if not os.path.exists(out_dir):
    os.makedirs(out_dir)

# Create operator
op = dpf.Operator("migrate_to_vtu")

# create a time scoping, here we select the last time step
time_support = model.TimeFreqSupport
num_sets = time_support.NumberSets
timeScoping = dpf.Scoping()
timeScoping.Ids = [num_sets]
timeScoping.Location = "Time"
# Connect inputs
op.Connect(4, model.DataSources) #input data source
op.Connect(0, timeScoping) #input time scoping
op.Connect(20, out_dir) #output directory
op.Connect(21, "vtu_surface") #output file base name

# Evaluate the operator
op.Run()

Required External VTU-to-VTP Conversion with PyVista

SimAI Pro training data is based on surface-result files, so the VTU file exported from Mechanical must be converted to VTP. This conversion should be performed outside Mechanical in a standard Python environment where the PyVista module can be imported. PyVista is not compatible with the IronPython engine used in Mechanical scripting. Beginning in 2026 R1, it is possible to switch the Python engine to CPython, which is compatible with PyVista. However, adding Python modules to the Mechanical Python environment is not straightforward, and file operations may be less predictable in some Mechanical CPython configurations. For these reasons, the current recommendation is to use IronPython for Mechanical scripting and perform the VTU-to-VTP conversion outside Mechanical. The following syntax shows how this can be done.

import pyvista as pv

# User inputs
vtu_file_path = r"C:\path\to\export\mechanical_results_T0000000-1.vtu"
vtp_file_path = r"C:\path\to\simai_training_data\design_001\surface.vtp"

# Read the VTU file exported from Mechanical
vtu_mesh = pv.read(vtu_file_path)

# Extract the exterior surface and save it as VTP
surface_mesh = vtu_mesh.extract_surface(algorithm="dataset_surface")
surface_mesh.save(vtp_file_path)

Validating the VTP Training-data File

The VTP file can be opened in a VTK-compatible viewer such as the open-source ParaView. Once opened, the model can be examined to confirm that the geometry is correct and that the required results are present.

  • Open the VTP file in ParaView or another VTK-compatible viewer.
  • Confirm that the extracted surface shape, units, and orientation match the Mechanical model.
  • Check that expected data arrays appear under point data or cell data.
  • Compare min/max values against the Mechanical result object for the same result set.

Troubleshooting Tips: Exporting Mechanical Results for SimAI Pro 

Issue Likely cause What to check
No VTU file is created Invalid output path or missing write permission Confirm the folder exists and Mechanical can write to it.
PyVista cannot be imported The conversion is being attempted inside Mechanical or in an environment without PyVista Run the VTU-to-VTP conversion in an external Python environment where PyVista is installed.
Unexpected result values Wrong time step, load step, or result operator Compare against the same result object and result set in Mechanical.

Conclusion

Mechanical scripting with DPF provides a repeatable way to extract solved Ansys Mechanical results and write them to VTU. For SimAI Pro training-data preparation, that VTU file is an intermediate step: the required surface-result file is created by converting VTU to VTP with PyVista outside Mechanical. Separating the workflow into a Mechanical export stage and an external PyVista conversion stage makes the process easier to automate, validate, and scale across many design points.

Exporting Mechanical Results for SimAI Pro: Example

This downloadable example contains an Ansys Mechanical model with the vtu conversion script included as a Python object under the Solution in the model tree. Solving the model can demonstrate the SimAI Pro capabilities described in this article.

Download: result_vtu_conversion.wbpz

mitchell-hortin-headshot

Mitchell Hortin, M.S. Mechanical Engineering
Senior Staff Engineer, SimuTech Group

Mitchell Hortin is a CAE engineer with 10 years of experience in structural analysis and engineering software development. He brings a strong foundation in computational mechanics, linear algebra, and system modeling, with extensive hands-on experience using, validating, and providing technical support for engineering analysis tools. His career spans both startups and large organizations, where he has built a track record of delivering high-quality work on schedule. Mitchell holds an M.S. in Mechanical Engineering from Brigham Young University with a focus on biomechanics and materials science, and is currently pursuing a Ph.D. emphasizing computational mechanics.

Recent Blog Posts