How to get stress result (all points) from a path using scriptin in mechanical for every time step?

Rohith Patchigolla
Rohith Patchigolla Member, Moderator, Employee Posts: 242
50 Answers 100 Comments Second Anniversary 25 Likes
✭✭✭✭

How to get stress result (all points) from a path using scriptin in mechanical for every time step?

Answers

  • Rohith Patchigolla
    Rohith Patchigolla Member, Moderator, Employee Posts: 242
    50 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭

    The below script loops through all the result sets and exports the Path result for each result set as a csv in the directory specified. This is done for the first analysis in the tree (if not please adjust the analysis index in ResData accordingly).

    Also, this shows an example method of extracting a result object based on Name. if you have multiple result objects with same name, please check things carefully. The code will work well if result objects have unique names.

    import os
    import context_menu
    
    ResData = ExtAPI.DataModel.Project.Model.Analyses[0].GetResultsData()
    DataSets = ResData.ListTimeFreq
    
    fileDir = r"D:\del\"
    
    pathObj = DataModel.GetObjectsByName("Equivalent Stress")[0]
    
    for displayTime in DataSets:
        pathObj.Activate()
        pathObj.DisplayTime = Quantity(displayTime,"s")
        context_menu.DoRetrieveResults(ExtAPI)
        fileName = pathObj.Name + "_" + str(displayTime) + ".csv"
        filePath = os.path.join(fileDir,fileName)
        pathObj.ExportToTextFile(filePath)