Goal:
Add results based on the number of load steps
Assign tags to created results based on scoping and type of result
Group results based on tags
Code:
# Get the number of steps for the analysis
analysis_settings = Model.Analyses[0].AnalysisSettings
number_of_steps = analysis_settings.NumberOfSteps
# Get the Named Selection of interest
solution = Model.Analyses[0].Solution
bolt = DataModel.GetObjectsByName("Bolt")[0] #This is a named selection!!
with Transaction():
# Create tags that will be used later for finding objects
tag2 = Ansys.Mechanical.Application.ObjectTag("Bolt")
tag3 = Ansys.Mechanical.Application.ObjectTag("U Sum")
tag4 = Ansys.Mechanical.Application.ObjectTag("EQV")
DataModel.ObjectTags.Add(tag2)
DataModel.ObjectTags.Add(tag3)
DataModel.ObjectTags.Add(tag4)
# For each step add the desired result objects with appropriate settings
for step in range(1, number_of_steps):
u_result = solution.AddTotalDeformation()
u_result.Name = "Total Deformation @ " + str(step) + " sec"
u_result.DisplayTime = analysis_settings.GetStepEndTime(step)
# Apply tags
tag3.AddObject(u_result)
s_result = solution.AddEquivalentStress()
s_result.Name = "Eqv Stress @ " + str(step) + " sec"
tag4.AddObject(s_result)
for step in range(1, number_of_steps):
u_result = solution.AddTotalDeformation()
u_result.Name = "Bolt Deformation @ " + str(step) + " sec"
u_result.Location = bolt
u_result.DisplayTime = analysis_settings.GetStepEndTime(step)
u_result.CalculateTimeHistory = False
tag2.AddObject(u_result)
tag3.AddObject(u_result)
s_result = solution.AddEquivalentStress()
s_result.Name = "Bolt Stress @ " + str(step) + " sec"
s_result.Location = bolt
tag2.AddObject(s_result)
tag4.AddObject(s_result)
tag2_list = tag2.Objects
tag3_list = tag3.Objects
tag4_list = tag4.Objects
# Find similar objects using the tags
u_all = [x for x in tag3_list if x not in tag2_list]
u_bolt = [x for x in tag3_list if x in tag2_list]
s_all = [x for x in tag4_list if x not in tag2_list]
s_Bolt = [x for x in tag4_list if x in tag2_list]
# Group similar objects
group = Tree.Group(u_all)
group.Name = "Total Deformation (All Bodies)"
group = Tree.Group(u_bolt)
group.Name = "Total Deformation (Bolt)"
group = Tree.Group(s_all)
group.Name = "Stress (All Bodies)"
group = Tree.Group(s_Bolt)
group.Name = "Stress (Bolt)"
Tree.Activate([solution])