How to export multiple Custom Results into csv files?

Gabriel Messager
Gabriel Messager Member, Employee Posts: 63
5 Answers Second Anniversary 10 Comments 5 Likes
✭✭✭✭
edited March 20 in 3D Design

I want to all the the Custom Results that containt prefix "CR_"

Comments

  • Gabriel Messager
    Gabriel Messager Member, Employee Posts: 63
    5 Answers Second Anniversary 10 Comments 5 Likes
    ✭✭✭✭
    import csv
    import wbjn
    import os
    
    userfilesdir = wbjn.ExecuteCommand(ExtAPI,"""returnValue(GetUserFilesDirectory())""")
    
    ansys_motion_objects = ExtAPI.DataModel.GetUserObjects("ANSYSMotion")
    function_expressions = filter(lambda x: x.Name == "CustomResult", ansys_motion_objects)
    for my_function_expression in function_expressions:
        if my_function_expression.Caption[:3] == "CR_":
            my_function_expression.Activate()
            tabular_data = my_function_expression.Controller.tabular
            num_rows = tabular_data.RowCount
            num_columns = tabular_data.ColumnCount
            table_list=[]
    
            with open(os.path.join(userfilesdir,my_function_expression.Caption)+'_data.csv', 'wb') as fp:
                writer = csv.writer(fp, delimiter=',')
                for row in range(0,num_rows):
                    row_list = []
                    for column in range(0,num_columns):
                        row_list.append(tabular_data.Cells[row,column].Text)
                    writer.writerow(row_list)