Export and save stress components to a file

Member, Moderator, Employee Posts: 311
50 Answers 100 Comments Second Anniversary 25 Likes
✭✭✭✭
edited November 2023 in General Language Questions

How can we Export and save stress components (x,y,z,xy,xz,yz) to a file?

Comments

  • Member, Moderator, Employee Posts: 311
    50 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭
    edited November 2023

    There are many ways of doing this (e.g., APDL, DPF, Mech scripting, etc.).

    One way of many possible is shown here. The mechanical script below, creates these results and saves them both in separate files, and in one single file.

    1. solution = ExtAPI.DataModel.Project.Model.Analyses[0].Solution
    2. normal_stressx = solution.AddNormalStress()
    3. normal_stressx.NormalOrientation = NormalOrientationType.XAxis
    4. normal_stressy = solution.AddNormalStress()
    5. normal_stressy.NormalOrientation = NormalOrientationType.YAxis
    6. normal_stressz = solution.AddNormalStress()
    7. normal_stressz.NormalOrientation = NormalOrientationType.ZAxis
    8. shear_stressxy = solution.AddShearStress()
    9. shear_stressxy.ShearOrientation=ShearOrientationType.XYPlane
    10. shear_stressxz = solution.AddShearStress()
    11. shear_stressxz.ShearOrientation=ShearOrientationType.XZPlane
    12. shear_stressyz = solution.AddShearStress()
    13. shear_stressyz.ShearOrientation=ShearOrientationType.YZPlane
    14. solution.EvaluateAllResults()
    15. ##separatefiles
    16. normal_stressx.ExportToTextFile("D:\mysx.txt")
    17. normal_stressy.ExportToTextFile("D:\mysy.txt")
    18. normal_stressz.ExportToTextFile("D:\mysz.txt")
    19. shear_stressxy.ExportToTextFile("D:\mysxy.txt")
    20. shear_stressxz.ExportToTextFile("D:\mysxz.txt")
    21. shear_stressyz.ExportToTextFile("D:\mysyz.txt")
    22. mysx=normal_stressx.PlotData
    23. ##one file
    24. plotDatasx= normal_stressx.PlotData.Values[2]
    25. plotDatasy= normal_stressy.PlotData.Values[2]
    26. plotDatasz= normal_stressz.PlotData.Values[2]
    27. plotDatasxy= shear_stressxy.PlotData.Values[2]
    28. plotDatasyz= shear_stressyz.PlotData.Values[2]
    29. plotDatasxz= shear_stressxz.PlotData.Values[2]
    30. nodes= normal_stressx.PlotData.Values[1]# list of node ids
    31. fpath = "D:/"
    32. fname = "mystresses.txt"
    33. f = open(fpath+fname,"w")
    34. for ii in range(0,len(nodes)):
    35. #print(node)
    36. f.write(str(nodes[ii]) +","+ str(plotDatasx[ii]) + "," + str(plotDatasy[ii]) + "," + str(plotDatasz[ii]) + ", " + str(plotDatasxy[ii])+ ", " + str(plotDatasyz[ii])+ ", " + str(plotDatasxz[ii]) +"\n")
    37. f.close()
This discussion has been closed.