How to get automatically x y z node locations and corresponding x y z displacements?

Member, Moderator, Employee Posts: 312
50 Answers 100 Comments Second Anniversary 25 Likes
✭✭✭✭
edited September 2024 in Structures

How can we read into arrays the x y z node locations and x y z displacements at these nodes?

Best Answer

  • Member, Moderator, Employee Posts: 312
    50 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭
    edited September 2024 Answer ✓

    There are many ways of doings this.

    Two possible ways are by using mechanical scripting.

    The first way is to use GetResultsData as shown here:

    https://discuss.ansys.com/discussion/2544/how-can-i-using-scripting-get-displacements-as-function-of-time-at-certain-areas

    Readapt the above to include more directions ( displacements).

    Another way is via the code shown below and at the end of this post (Readapt script to include more directions ( displacements).

    We can also use DPF to do this - the following code (see link below) can be easily adapted to read displacements instead of temperatures (e.g., use dpf.operators.result.displacement_Y for y-disp).

    https://discuss.ansys.com/discussion/2383/print-temperatures-node-ids-and-locations-using-dpf-inside-mechanical

    Script mentioned above (exports and reads data back into arrays):

    1. analysis=ExtAPI.DataModel.Project.Model.Analyses[0]
    2. solution=analysis.Solution
    3. dirdef=solution.AddDirectionalDeformation() # add as many times as needed for x, y, z
    4. dirdef.NormalOrientation=NormalOrientationType.ZAxis
    5. solution.EvaluateAllResults()
    6. dirdef.ExportToTextFile("D:/dispz.csv")
    7.  
    8. #read data in from export file above
    9. import csv
    10. nodenr=[]
    11. cx=[]
    12. cy=[]
    13. cz=[]
    14. dirdis=[]
    15. with open("D:/dispz.csv", 'rb') as f:
    16. reader = csv.reader(f)
    17. next(reader)
    18. for row in reader:
    19. print(row)
    20. nodenr.append(row[0].split('\t')[0])
    21. cx.append(row[0].split('\t')[1])
    22. cy.append(row[0].split('\t')[2])
    23. cz.append(row[0].split('\t')[3])
    24. dirdis.append(row[0].split('\t')[4])
This discussion has been closed.