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

Erik Kostson
Erik Kostson Member, Moderator, Employee Posts: 276
50 Answers 100 Comments Second Anniversary 25 Likes
✭✭✭✭

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 Answers

  • Erik Kostson
    Erik Kostson Member, Moderator, Employee Posts: 276
    50 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭
    edited October 1 Answer ✓

    There are many ways of doings this. 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()
    
  • Erik Kostson
    Erik Kostson Member, Moderator, Employee Posts: 276
    50 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭
    edited October 1 Answer ✓

    Even though this is not a mechanical/mapdl forum , but for the sake of completeness to the above script, in a similar way, this can be done (one node only) using an apdl command snippet (placed under the Solution in the Mech. tree).

    *get,my_steps, ACTIVE, 0,SET,SBST
    *cfopen,'D:\\test\\vw1.txt'
    *DO,j,1,my_steps,1
    my_nodenr=113
    SET,1,j
    *get,my_time, ACTIVE, 0,SET,TIME
    *get,my_uz,node,my_nodenr,u,z
    *VWRITE,'Time: ', my_time, 'Node', my_nodenr, ' UZ ' , my_uz
    (A12, E13.5, A12, E13.5, A12, E13.5) 
    *ENDDO
    *cfclose
    
    
This discussion has been closed.