How to access Tabular data using ACT?

Member, Employee Posts: 201
100 Likes 100 Comments Second Anniversary Ansys Employee
✭✭✭✭
edited December 2023 in Structures

How to access Tabular data using ACT?

Tagged:

Welcome!

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

Best Answers

  • Member, Employee Posts: 201
    100 Likes 100 Comments Second Anniversary Ansys Employee
    ✭✭✭✭
    Answer ✓

    It's possible using the following unsupported code :

    1. paneTabular=ExtAPI.UserInterface.GetPane(MechanicalPanelEnum.TabularData)
    2. control = paneTabular.ControlUnknown
    3. for col in range(1,control.ColumnsCount+1):
    4. for row in range(1,control.RowsCount+1):
    5. cellText= control.cell(row ,col ).Text
    6. if cellText!=None:
    7. print cellText
  • Member, Employee Posts: 251
    50 Answers 100 Comments 100 Likes Second Anniversary
    ✭✭✭✭
    Answer ✓

    I enhanced your solution to write the table to a csv:

    1. import os
    2. import csv
    3. directory = 'D:/'
    4.  
    5. for analysis in Model.Analyses:
    6. for solution in analysis.Solution.Children:
    7. if solution.Name != 'Solution Information':
    8. solution.Activate()
    9. paneTabular=ExtAPI.UserInterface.GetPane(MechanicalPanelEnum.TabularData)
    10. control = paneTabular.ControlUnknown
    11. num_columns = control.ColumnsCount+1
    12. num_rows = control.RowsCount+1
    13. result = []
    14. for row in range(1,num_rows):
    15. r = []
    16. for col in range(1,num_columns):
    17. r.append(control.cell(row ,col ).Text)
    18. result.append(r)
    19. save_name = os.path.join(directory, analysis.Name + ' '+ solution.Name+'.csv')
    20. with open(save_name, 'w') as f:
    21. writer = csv.writer(f)
    22. writer.writerows(result)

    This will write all tabular solution data to a csv. Please tell me there is a better way.

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

    It seems there is now (2021R2) a better way to access Tabular Data:

    1. TOTAL_DEFORMATION_1 = SOLUTION.AddTotalDeformation()
    2. FREQ1 = TOTAL_DEFORMATION_1.TabularData["Frequency"][0]

    See https://ansyshelp.ansys.com/account/secured?returnurl=/Views/Secured/corp/v212/en/act_script/act_script_demo_modal_acoustic.html for further reference.

  • Member, Employee Posts: 251
    50 Answers 100 Comments 100 Likes Second Anniversary
    ✭✭✭✭
    Answer ✓

    Here is a way to fill in a tabular data from an imported csv. The example here is a heat flow import (so the quantity units are sec and W).

    At the end, the time for the analysis settings is set.

    Thanks to Chems.

    1. import csv
    2. myData = r"D:\my\path\heatFlow.csv"
    3. rows = []
    4.  
    5. with open(myData, 'r') as file:
    6. csvreader = csv.reader(file)
    7. header = next(csvreader)
    8. for row in csvreader:
    9. rows.append(row)
    10.  
    11. timeSteps = len(rows)
    12. analysis = ExtAPI.DataModel.Project.Model.Analyses[0]
    13.  
    14. myTimes = [Quantity(float(i[0]), "sec") for i in rows] # create quantity lists for Discrete input
    15. myFlow = [Quantity(float(i[1]), "W") for i in rows]
    16.  
    17. myHeatFlow = analysis.AddHeatFlow()
    18. myMag = myHeatFlow.Magnitude
    19. myMag.Inputs[0].DiscreteValues = myTimes
    20. myMag.Output.DiscreteValues = myFlow
    21.  
    22. ## You might want to check this, it seems to work and avoid the duplication of the steps but might add 1 extra (+1) !!
    23. analysis.AnalysisSettings.NumberOfSteps = timeSteps
    24. with Transaction(suspendClicks=True):
    25. for t0 in range(timeSteps):
    26. analysis.AnalysisSettings.CurrentStepNumber= t0+1
    27. analysis.AnalysisSettings.StepEndTime = myTimes[t0+1]

Answers

Welcome!

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