Export result data

Member, Moderator, Employee Posts: 873
100 Answers 500 Comments 250 Likes Second Anniversary
✭✭✭✭
edited June 2023 in Structures

From a Mechanical simulation, I would like to export result data

Tagged:

Best Answer

  • Member, Moderator, Employee Posts: 873
    100 Answers 500 Comments 250 Likes Second Anniversary
    ✭✭✭✭
    Answer ✓

    The easiest way will be to use the ExportToTextFile() method, as follows:

    1. import os
    2. export_folder = r'D:\Data'
    3.  
    4. analysis = ExtAPI.DataModel.Project.Model.Analyses[0]
    5. solution = analysis.Solution
    6.  
    7. total_deformation = solution.Children[1]
    8. print(total_deformation.Name)
    9.  
    10. export_name = os.path.join(export_folder,total_deformation.Name)
    11. total_deformation.ExportToTextFile(export_name + '.txt')

    Another option is to use the PlotData property and export the values inside it, for example to a .json file. To be dumped into a json format the data needs to be serializable, which is not the case of PlotData. However we can extract the data contained in PlotData, add it to a dictionnary, and then dump the dictionnary to the .json file, as below:

    1. import json
    2.  
    3. result_values= total_deformation.PlotData["Values"]
    4. node_list=total_deformation.PlotData["Node"]
    5. data_dict = {}
    6. for i in range(len(node_list)):
    7.     data_dict[node_list[i]] = result_values[i]
    8.  
    9. with open(export_name +'.json', 'w') as f:
    10.     json.dump(data_dict, f)

Welcome!

It looks like you're new here. Sign in or register to get started.