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

Erik Kostson
Erik Kostson Member, Employee Posts: 209
50 Answers 100 Comments Photogenic 5 Likes
✭✭✭✭
edited September 12 in Structures

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

Best Answer

  • Erik Kostson
    Erik Kostson Member, Employee Posts: 209
    50 Answers 100 Comments Photogenic 5 Likes
    ✭✭✭✭
    edited September 12 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):

    analysis=ExtAPI.DataModel.Project.Model.Analyses[0]
    solution=analysis.Solution
    dirdef=solution.AddDirectionalDeformation() # add as many times as needed for x, y, z
    dirdef.NormalOrientation=NormalOrientationType.ZAxis
    solution.EvaluateAllResults()
    dirdef.ExportToTextFile("D:/dispz.csv")
    
    #read data in from export file above
    import csv
    nodenr=[]
    cx=[]
    cy=[]
    cz=[]
    dirdis=[]
    with open("D:/dispz.csv", 'rb') as f:
        reader = csv.reader(f)
        next(reader)
        for row in reader:
            print(row)
            nodenr.append(row[0].split('\t')[0])
            cx.append(row[0].split('\t')[1])
            cy.append(row[0].split('\t')[2])
            cz.append(row[0].split('\t')[3])
            dirdis.append(row[0].split('\t')[4])
    
This discussion has been closed.