DPF is sometimes a bit difficult to work with. I got tired of trying to remember what worked and so I dug around until I found the list of available results (from the model.metadata) and the time steps in my .rst to create a method that would always work.
The script below will plot as default the displacement for the first time step, which, at least in my world, is always available.
But you can look in the ResultSetList parameter and see what time steps are available and set the plot to any set in that list.
And you can look in the resultDict or fullList and see what results are available. You need to use the exact string names to get the method to work because I am using a getattr() in python to complete the result command. (The gettattr command in python is just a way to get the dot notation completion from an input. )
from ansys.dpf import core as dpf
version = 261
server = dpf.start_local_server(ansys_path=r"C:\Program Files\ANSYS Inc\v{v}".format(v=version))
path =r"path\to\my\file.rst"
# What I want to plot
timestep = 1
plottype = 'displacement' # change this to something in the fullList
# import the model/rst using dpf
model = dpf.Model(path)
print(model)
metadata1 = model.metadata
# use the model data to determine what is available in the .rst file
# The resultDict has the available data as key (category) and plottype (sub-category or item/value)
# The resultSetList is the list of time steps available in the resultl
# In the end the plottype string and timestep integer are used for plotting below
resultsSets = model.metadata.time_freq_support.n_sets
resultSetList = [str(i) for i in range(resultsSets)]
results = [i.name for i in metadata1.result_info.available_results]
fullList = dir(dpf.operators.result)
resultDict = {}
for resultkey in results:
resultDict[resultkey] = [i for i in fullList if resultkey in i and 'compute' not in i]
# plot commands using data from above
time_sets_scoping = dpf.time_freq_scoping_factory.scoping_by_sets([timestep])
resOp = getattr(dpf.operators.result, plottype)(data_sources = model, time_scoping = time_sets_scoping)
resOpFieldContainer = resOp.outputs.fields_container()[0]
model.metadata.meshed_region.plot(resOpFieldContainer,notebook = False, text = plottype + ' - Time Step : ' + str(timestep))