Skip to main content
Let’s create a simple script in the Ansys Mechanical scripting window to access and extract result data using DPF.

Using the Mechanical scripting window

Open Ansys Mechanical and access View → Scripting, then enter:

Step-by-Step explanation

1. Import required modules

Import both the mech_dpf helper module and the main DPF namespace. Both are available in Mechanical’s IronPython environment.

2. Set ExtAPI context (CRITICAL!)

This step is required to properly initialize DPF with the Mechanical API context. Without this, many DPF operations will fail.

3. Access Mechanical analysis

Get the first analysis from the current Mechanical model.

4. Get result file path

Retrieve the path to the result file (.rst) from the analysis object.

4. Create DPF data source

Create a DPF data source pointing to your result file.

5. Create DPF model

The DPF Model object provides access to all result data and metadata.

Using DPF operators

DPF uses an operator-based approach for data processing. Here’s an example extracting stress:

Using in a Python Result object

You can also use DPF in a Python Result object for visualization:
Key points for Python Result objects:
  • Must use define_dpf_workflow(analysis) function
  • Create dpf.Workflow() for visualization
  • Use SetOutputContour() to specify what to plot
  • Call Record() and set this.WorkflowId

Generating DPF documentation

To generate comprehensive DPF documentation in Mechanical:
This will display the path to the DPF HTML documentation file.

What’s next?

Now that you’ve run your first script in Mechanical, explore: