Skip to main content

Motion Standalone Postprocessor C# library 2026 R1

Example

Last update: 09.03.2026

The following sample code illustrates how to create a simple example.

  • The examples provided below can be found within the 'Install_Path\Motion\Document\Postprocessor API for Python.zip' compressed file.

Create a Coordinate System

The Coordinate system can be created from various entities in the result as below, and this example describes how to create the Coordinate System.

  • Rigid Body
  • FE Node
  • Marker
# Example_ResultFileReaderAPI_CoordinateSystem.py
import sys
from pathlib import Path

# Get the current file's path and set the path for external modules.
current_dir = Path(__file__).resolve().parent
external_modules_path = Path(current_dir, r'../../Modules').resolve()
sys.path.append('{0}'.format(external_modules_path))

# Import necessary modules
from ResultFileReaderAPI import *

# Import result file
outputReader = OutputReader(get_result_file_path())

# Create a Coordinate System
# Name - Set the name of instance.
# ParentInfo - Specifies The path of an parent entity.
crank_csys = outputReader.CreateCoordinateSystem("Crank_CSYS", "Crank")
crank_csys.TransformationOffsetParameters.Angle = Vector(0, 10, 0)
crank_csys.TransformationOffsetParameters.Position = Vector(10, 10, 10)
crank_csys.TransformationOffsetParameters.RotationAxis = RotationAxes.XYZ # XYX, XYZ, XZX, XZY, YXY, YXZ, YZX, YZY, ZXY, ZXZ, ZYX, ZYZ
crank_csys.TransformationOffsetParameters.RotationType = RotationTypes.FixedAngle # EulerAngle, FixedAngle

# The GeneralMarkerType property indicates Type attribute as displayed in the user interface.
# Accepted input values are defined by the GeneralMarkerType enumeration.
# The GeneralMarkerType ρ property must be one of the following: CARTESIAN, CYLINDRICAL, SPHERICAL
crank_csys.GeneralMarkerType = GeneralMarkerType.CYLINDRICAL

if crank_csys.GeneralMarkerType == GeneralMarkerType.SPHERICAL:
    # The PrimaryAxis property indicates Axis ρ. Accepted input values are defined by the CoordinateType enumeration.
    # The Axis ρ property must be one of the following: X, Y, Z
    crank_csys.PrimaryAxis = CoordinateType.X
    # The PrimaryAxis property indicates Axis Ø. Accepted input values are defined by the CoordinateType enumeration.
    # The Axis Ø property must be one of the following: X, Y, Z    
    crank_csys.SecondaryAxis = CoordinateType.Y
elif crank_csys.GeneralMarkerType == GeneralMarkerType.CYLINDRICAL:
    # The PrimaryAxis property indicates Axis R. Accepted input values are defined by the CoordinateType enumeration.
    # The Axis R property must be one of the following: X, Y, Z
    crank_csys.PrimaryAxis = CoordinateType.Z
    # The SecondaryAxis property indicates Axis Z. Accepted input values are defined by the CoordinateType enumeration.
    # The Axis Z property must be one of the following: X, Y, Z    
    crank_csys.SecondaryAxis = CoordinateType.X

# Rigid Body
print (f"Marker Name : {crank_csys.FullName}")

# Create a Coordinate System
# Name - Set the name of instance.
# ParentInfo - Specifies The path of an parent entity.
fenode_csys = outputReader.CreateCoordinateSystem("NodeCSYS", "FEBody_01/Node/754")
print (f"Marker Name : {fenode_csys.FullName}")

# Create a Coordinate System
# Name - Set the name of instance.
# ParentInfo - Specifies The path of an parent entity.
marker_csys = outputReader.CreateCoordinateSystem("MarkerCSYS", "Crank/CM")
print (f"Marker Name : {marker_csys.FullName}")

# Close
outputReader.Close() 

Plot

It is the simplest example of a Python script to print plot data.

Plot

# Example_ResultFileReader_Plot.py
import sys
from pathlib import Path

# Get the current file's path and set the path for external modules.
current_dir = Path(__file__).resolve().parent
external_modules_path = Path(current_dir, r'../../Modules').resolve()
sys.path.append('{0}'.format(external_modules_path))

# Import necessary modules
from ResultFileReaderAPI import *

# Import result file
# Create an OutputReader instance to read the result file.
outputReader = OutputReader(get_result_file_path())

# Specify the paths for the curves you want to retrieve.
# For example, Acceleration represents the Characteristic, and Y after the / represents the Component.
# In this case, we are retrieving the Y component of Acceleration for the Crank.
# You can check the available Characteristics and Components for the target by using Add Curve in the Postprocessor.
paths = List[str]() 
paths.Add("Acceleration/Y")

# Create a PlotParameters object to specify the parameters for the plot.
plotParameter = PlotParameters()

# Set the Entity to Plot.
# The Target is the name of the target for which you want to retrieve the curves.
plotParameter.Target = "Crank"

# Set the paths for the curves you want to retrieve.
# This is where you specify the characteristics and components you want to plot.
plotParameter.Paths = paths

# There are two ways to retrieve the results of the curve:
# 1. PlotDataType.DEFAULT - Uses the default PlotDataType setting.
# 2. PlotDataType.PlotResult - If a Plt result exists, you can set PlotResult and obtain the result from Plt.
# If PlotDataType is not set, it is set to Default by default.
plotParameter.PlotDataType = PlotDataType.DEFAULT

# Get curve data from the result.
results = outputReader.GetCurves(plotParameter)

# Print the results in a formatted way.
for result in results :
    print(['Time\t', "Y", '\n'])
    for plotData in result.Value :
        print([str(plotData.X), '\t', str(plotData.Y), '\n'])
 
# Close
outputReader.Close()

Contour Export

Export contour results to a file

# Example_ResultFileReaderAPI_Contour.py
import struct, os, sys
from pathlib import Path

# Get the current file's path and set the path for external modules.
current_dir = Path(__file__).resolve().parent
external_modules_path = Path(current_dir, r'../../Modules').resolve()
sys.path.append('{0}'.format(external_modules_path))

# Import necessary modules
from ResultFileReaderAPI import *

# Import result file
outputReader = OutputReader(get_result_file_path())

output_dir = get_output_directory()
export_result_file_path = os.path.join(output_dir, r'ExportContourResultToFile.txt')

# State ID Array
stateids = outputReader.GetStateIDArray()
path = "Top Stress/X"

# GetGeometryInfoArray
geometries = outputReader.GetGeometryInfoArray()

# Find Item
febody = next((item for item in geometries if item.FullName == "FEBody_01"), None)

# resultpath - Specifies the file path to export
# mode - Specifies how the operating system should open a file.
# stateids - Specifies the id list of the states to time.
# fullName - Specifies the names of the entities.
# type - Specifies the type of the target for displaying contour(None, FENode, FEElement, FEElementNode, FEMaterial, BeamGroup, Contact, ChainedSystem, Usersubroutine).
# path - Specifies the path of result to save.
# analysisResultType - Specifies the type of analysis result type for displaying contour.
# formatType - Specifies a file format type.
outputReader.ExportContourResultToFile(export_result_file_path, FileMode.Create, stateids, febody.FullName, ContourMappingType.FENode, path, analysisResultType = AnalysisResultType.Dynamics, formatType = FileFormatType.BINARY)

stateids = outputReader.GetStateIDArray()
totalsteps = len(list(stateids))
datapart = outputReader.GetGeometryInfo(febody.FullName)
nnodes = datapart.NodesCount
timearray = outputReader.GetReferenceTimeArray()

print('===================== Top Stress X =======================:')
print('total steps :', totalsteps)
print('total nodes :', nnodes)
with open(export_result_file_path, 'rb') as file:
    for id in stateids:
        print('===================== state id =======================:', id)
        print('===================== ref time =======================:', timearray[id-1])
        double_values = struct.unpack('d' * nnodes, file.read(struct.calcsize('d') * nnodes))
        
        print(*double_values, sep=',')
        print(f"\n")

# Close
outputReader.Close()

Vector Export

Export vector results to a file

# Example_ResultFileReaderAPI_ExportVectorFile.py
import os, sys
from pathlib import Path

# Get the current file's path and set the path for external modules.
current_dir = Path(__file__).resolve().parent
external_modules_path = Path(current_dir, r'../../Modules').resolve()
sys.path.append('{0}'.format(external_modules_path))

# Import necessary modules
from ResultFileReaderAPI import *

# Import result file
outputReader = OutputReader(get_result_file_path())

stateids = outputReader.GetStateIDArray()

# target - Specifies the name of vector displayable entity
# path - Specifies characteristc on vector display
target = "TJ_01"
path = "Base Force"

targets = List[IVectorDisplay]()
vector = outputReader.CreateVector("vector", target, path)
targets.Add(vector)
print ("===ExportVectorDisplayToFile===")

output_dir = get_output_directory()
export_vector_file_path = os.path.join(output_dir, r'ExportVectorDisplayToFile_Targets.txt')
outputReader.ExportVectorDisplayToFile(export_vector_file_path, stateids, targets, True, True, True, AnalysisResultType.Dynamics)

export_vector_file_path = os.path.join(output_dir, r'ExportVectorDisplayToFile_Target.txt')
outputReader.ExportVectorDisplayToFile(export_vector_file_path, stateids, "TJ_01", "Base Force", True, True, True, AnalysisResultType.Dynamics)

# Close
outputReader.Close()

Get Vector

Get results from the Vector.

# Example_ResultFileReader_Vector.py
import sys
from pathlib import Path

# Get the current file's path and set the path for external modules.
current_dir = Path(__file__).resolve().parent
external_modules_path = Path(current_dir, r'../../Modules').resolve()
sys.path.append('{0}'.format(external_modules_path))

# Import necessary modules
from ResultFileReaderAPI import *

# Import result file
outputReader = OutputReader(get_result_file_path())

print ("===GetVector===")
# target - Specifies the name of vector displayable entity
# path - Specifies characteristc on vector display
vectors = outputReader.GetVector("TJ_01", "Action Force")
for vector in vectors:
    print(f"Vector : {vector.Key}")
    animation_data = vector.Value

    positions = len(list(animation_data.Positions))
    for i in range(positions):
        first_positions = len(list(animation_data.Positions[i]))
        for j in range(first_positions):
            second_positions = list(animation_data.Positions[i][j])
            print("Positions :", *second_positions, sep=',')

    vectors = len(list(animation_data.Vectors))
    for i in range(vectors):
        first_vectors = len(list(animation_data.Vectors[i]))
        for j in range(first_vectors):
            second_vectors = list(animation_data.Vectors[i][j])
            print("Vectors :", *second_vectors, sep=',')
# Close
outputReader.Close()

Connect with Ansys