How to access Tabular data using ACT?

Chemsdine CHEMAI
Chemsdine CHEMAI 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:

Best Answers

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

    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
    
  • M
    M Member, Employee Posts: 239
    50 Answers 100 Comments 100 Likes Second Anniversary
    ✭✭✭✭
    Answer ✓

    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.

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 871
    100 Answers 500 Comments 250 Likes First Anniversary
    ✭✭✭✭
    Answer ✓

    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.

  • M
    M Member, Employee Posts: 239
    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.

    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]
    

Answers

  • M
    M Member, Employee Posts: 239
    50 Answers 100 Comments 100 Likes Second Anniversary
    ✭✭✭✭

    Annoying fact, fails w/ CPython

  • Mike.Thompson
    Mike.Thompson Member, Employee Posts: 342
    25 Answers 100 Comments 25 Likes First Anniversary
    ✭✭✭✭

    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.

  • Ben Klinkhammer
    Ben Klinkhammer Member, Employee Posts: 5
    Name Dropper First Comment
    ✭✭✭

    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,
    Ben

  • Mike.Thompson
    Mike.Thompson Member, Employee Posts: 342
    25 Answers 100 Comments 25 Likes First Anniversary
    ✭✭✭✭

    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.

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 871
    100 Answers 500 Comments 250 Likes First Anniversary
    ✭✭✭✭

    For the specifics of tabular data in Motion, @Gabriel Messager might have an example.