How to access Tabular data using ACT?


Best Answers
-
It's possible using the following unsupported code :
paneTabular=ExtAPI.UserInterface.GetPane(MechanicalPanelEnum.TabularData) control = paneTabular.ControlUnknown for col in range(1,control.ColumnsCount+1): for row in range(1,control.RowsCount+1): cellText= control.cell(row ,col ).Text if cellText!=None: print cellText
4 -
I enhanced your solution to write the table to a csv:
import os import csv directory = 'D:/' for analysis in Model.Analyses: for solution in analysis.Solution.Children: if solution.Name != 'Solution Information': solution.Activate() paneTabular=ExtAPI.UserInterface.GetPane(MechanicalPanelEnum.TabularData) control = paneTabular.ControlUnknown num_columns = control.ColumnsCount+1 num_rows = control.RowsCount+1 result = [] for row in range(1,num_rows): r = [] for col in range(1,num_columns): r.append(control.cell(row ,col ).Text) result.append(r) save_name = os.path.join(directory, analysis.Name + ' '+ solution.Name+'.csv') with open(save_name, 'w') as f: writer = csv.writer(f) writer.writerows(result)
This will write all tabular solution data to a csv. Please tell me there is a better way.
0 -
It seems there is now (2021R2) a better way to access Tabular Data:
TOTAL_DEFORMATION_1 = SOLUTION.AddTotalDeformation() 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.
2 -
I needed to get a value out of a Python Result so I adapted the scripts above to grab the tabular data (the only results I could find in the GUI).
def getResMax(): paneTabular=ExtAPI.UserInterface.GetPane(MechanicalPanelEnum.TabularData) control = paneTabular.ControlUnknown col= control.ColumnsCount row = control.RowsCount maxval = control.cell(row ,col ).Text return maxval
it just grabs the last row/col data from the active table. This should be the maximum. But a myResultThatHasATable.Activate() is necessary.
6 -
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.
import csv myData = r"D:\my\path\heatFlow.csv" rows = [] with open(myData, 'r') as file: csvreader = csv.reader(file) header = next(csvreader) for row in csvreader: rows.append(row) timeSteps = len(rows) analysis = ExtAPI.DataModel.Project.Model.Analyses[0] myTimes = [Quantity(float(i[0]), "sec") for i in rows] # create quantity lists for Discrete input myFlow = [Quantity(float(i[1]), "W") for i in rows] myHeatFlow = analysis.AddHeatFlow() myMag = myHeatFlow.Magnitude myMag.Inputs[0].DiscreteValues = myTimes myMag.Output.DiscreteValues = myFlow ## You might want to check this, it seems to work and avoid the duplication of the steps but might add 1 extra (+1) !! analysis.AnalysisSettings.NumberOfSteps = timeSteps with Transaction(suspendClicks=True): for t0 in range(timeSteps): analysis.AnalysisSettings.CurrentStepNumber= t0+1 analysis.AnalysisSettings.StepEndTime = myTimes[t0+1]
0
Answers
-
Annoying fact, fails w/ CPython
0 -
This seems like it is not a general purpose solution for all tabular data (as of 2022.2) We can get it for Frequency, but not many other data types are supported, and it seems to return an error when trying to access TabularData for other types of columns.
0 -
Hi @Pernelle Marone-Hitz and @Mike.Thompson
This seems to work for me for proper Tabular Data in Mechanical, but I can't seem to get it to work for tabular data coming from motion, etc where non-standard tables are used.
For example, I want to extract some shaft sections out to a csv file, but I can't figure out how to access that tabular data (see pic below)Any help would be appreciated!
Thanks,
Ben0 -
There is a template available in the ACT templates on the customer portal. There is one specific for an example of this kind of tabular data for both the xml setup and the python usage.
0 -
For the specifics of tabular data in Motion, @Gabriel Messager might have an example.
0