An excellent question.
If you have a model with multiple time steps you can use a python code object to grab the time and create a unique python result.
The python code object script example below will get the time steps:
#analysis = ExtAPI.DataModel.Project.Model.Analyses[0]
steps = analysis.AnalysisSettings.NumberOfSteps
solution = analysis.Solution
and if you have a pre prepared text for a python result:
myPR = """def post_started(sender, analysis):# Do not edit this line
define_dpf_workflow(analysis)
def define_dpf_workflow(analysis):
step = float({step})
import mech_dpf
import Ans.DataProcessing as dpf
mech_dpf.setExtAPI(ExtAPI)
dataSource = dpf.DataSources(analysis.ResultFileName)
u = dpf.operators.result.displacement()
nrm = dpf.operators.math.norm_fc()
u.inputs.data_sources.Connect(dataSource)
nrm.Connect(u)
scale_op = dpf.operators.math.scale()
scale_value = float(step)
scale_op.inputs.ponderation.Connect(scale_value)
scale_op.inputs.field.Connect(nrm)
dpf_workflow = dpf.Workflow()
dpf_workflow.Add(u)
dpf_workflow.Add(nrm)
dpf_workflow.SetInputName(u, 0, 'time')
dpf_workflow.Connect('time', step)
dpf_workflow.SetOutputContour(scale_op)
dpf_workflow.Record('wf_id', False)
this.WorkflowId = dpf_workflow.GetRecordedId()
"""
You can loop through the time steps to use the myPR text to a series of python results and append (using .format()) any required changes to the python result you need. Here I just set a parameter, step, and that is used in the script below to set the time of the result and a scaling factor.
Note the weird indentation in the triple quoted text. That is required to get it to format properly in the python result.
for step in range(steps):
print(step)
pr = solution.AddPythonResult()
pr.Name = 'def_step_' + str(step)
pr.Text = myPR.format(step=step)
pr.Connect()
pr.ReloadProperties()
solution.EvaluateAllResults()
The .format command can of course be used to add more than one value into the python result text. Just put the name parameter={parameter} in the curly brackets and add another parameter to the format statement at the end .format(step=step,parameter=parameter) when you write it to the python result.
You can adapt this in an After Solve Python Code Object and it should generate a python result with the time step variable as a scale parameter in each.