How can I using scripting get displacements as function of time at certain areas ?

Erik Kostson
Erik Kostson Member, Employee Posts: 87
First Answer Name Dropper First Anniversary Ansys Employee
edited September 2023 in General Language Questions

We have a named selection in a mechanical transient (structural) system and we want to write all of the displacement for every time step to a text file for further post processing. How can we do that using mechanical scripting?

Best Answer

  • Erik Kostson
    Erik Kostson Member, Employee Posts: 87
    First Answer Name Dropper First Anniversary Ansys Employee
    edited October 2023 Answer ✓

    Below is a sample script that does that (gets the nodes of the 1st named selection):

    model=ExtAPI.DataModel.Project.Model # refer to Model
    reader = model.Analyses[0].GetResultsData() # get results data of first analysis in the tree
    analysis = model.Analyses[0]
    
    ns=model.NamedSelections.Children
    nodeids=ns[0].Location.Ids # change nodal named selection / picks the 1st one 
    
    DataSets=reader.ListTimeFreq
    
    
    f1=open("D:\\test.txt","w") #open file in user directory
    for node in nodeids:
        for si in range(0,len(DataSets),1):
            reader.CurrentTimeFreq = DataSets[si]
            myDeformation = reader.GetResult("U")
            deformynode = myDeformation.GetNodeValues(node)[1] # y -disp[1]
            nx=ExtAPI.DataModel.MeshDataByName("Global").NodeById(node).X
            f1.write(str(float(DataSets[si]))+ " ,"  + str(node)+ " , " + str(nx)+ " , " +str(deformynode) +"\n")
    f1.close()