Write max vm stress for each part in named selection to file
Erik Kostson
Member, Employee Posts: 233
✭✭✭✭
In short using mech scripting, we would like to write e.g., max vm stress for each part in named selection to a text file.
Tagged:
0
Best Answers
-
One way of doing this is presented below:
model=ExtAPI.DataModel.Project.Model # refer to Model analysis = model.Analyses[0] solution = analysis.Solution f1=open("D:\\testpartvmstress.txt","w") #open file in user directory change as needed ns=model.NamedSelections.Children[0] # change named selection as needed / picks the first one in tree, contains all parts to be used below nIds=ns.Location.Ids for body in nIds: res=solution.AddEquivalentStress() selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities) selection.Ids=[body] res.Location=selection selection=ExtAPI.SelectionManager.ClearSelection() res.EvaluateAllResults() partname=res.MinimumOccursOn parmax=res.Maximum f1.write(partname + " , " + str(parmax) +","+ "\n") f1.close()
If we want to do it for all parts in Mechanical (so no need to add relevant parts in Named Selection):
model=ExtAPI.DataModel.Project.Model # refer to Model analysis = model.Analyses[0] solution = analysis.Solution f1=open("D:\\testpartvmstress.txt","w") #open file in user directory change as needed for assembly in ExtAPI.DataModel.GeoData.Assemblies: for part in assembly.Parts: for body in part.Bodies: res=solution.AddEquivalentStress() selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities) selection.Ids=[body.Id] res.Location=selection selection=ExtAPI.SelectionManager.ClearSelection() res.EvaluateAllResults() partname=res.MinimumOccursOn parmax=res.Maximum f1.write(partname + " , " + str(parmax) +","+ "\n") f1.close()
0 -
Finally if we want to loop over named selections and get the maximum in each named selection:
model=ExtAPI.DataModel.Project.Model # refer to Model analysis = model.Analyses[0] solution = analysis.Solution f1=open("D:\\testpartvmstress.txt","w") #open file in user directory change as needed ns=model.NamedSelections.Children for nsi in ns: nIds=nsi.Location.Ids res=solution.AddEquivalentStress() res.Location=nsi res.EvaluateAllResults() partname=res.MinimumOccursOn parmax=res.Maximum f1.write(str(nsi.Name) + " , " + str(partname) + " , " + str(parmax) +" , "+ "\n") f1.close()
0
This discussion has been closed.