How can we export results to text file and then combine all files into one file

Options
Erik Kostson
Erik Kostson Member, Employee Posts: 164
First Comment First Answer Name Dropper First Anniversary
edited June 2023 in Structures

How can we export results to a text file and then combine all files into one file automatically?

Tagged:

Answers

  • Erik Kostson
    Erik Kostson Member, Employee Posts: 164
    First Comment First Answer Name Dropper First Anniversary
    Answer ✓
    Options

    Similar question has been asked in the Ansys learning forum, and the answer to this is:

    global files
    files=[]
    anls=ExtAPI.DataModel.Project.Model.Analyses
    
    maxnls=len(anls)
    
    for j in range(0,maxnls):
        res=anls[j].Solution.Children
        maxres=len(res)
        for i in range(1,maxres):
            res[i].ExportToTextFile(bool,'''D:\'''+str(res[i].Name)+'''_nls_'''+str(j)+'''_'''+str(i)+'''.txt''')
            files.append('''D:\'''+str(res[i].Name)+'''_nls_'''+str(j)+'''_'''+str(i)+'''.txt''')
    
    
    with open("D:\output_file.txt", "w") as outfile:
        for filename in files:
            with open(filename) as infile:
                contents = infile.read()
                outfile.write(contents)