We have an exciting announcement about badges coming in May 2025. Until then, we will temporarily stop issuing new badges for course completions and certifications. However, all completions will be recorded and fulfilled after May 2025.
General Mechanical

General Mechanical

Topics related to Mechanical Enterprise, Motion, Additive Print and more.

Tabular Data Extraction

    • douglas99
      Subscriber

      Hello Everone,


      I am excited to be using ANSYS for a Senior Class project. I have been creating Extension with script files (.xml and .py) using the ANSYS ACT tool and ran into a rather difficult problem. I have created a Image Capturing extension, Path Creation extension, but I am having problems with the Plotting Extension. I cannot find the API for extracting the Tabular Data that shows up in the Tabular Data tab when you are done plotting and simulating a meshed object so that I can extract it into my extension. In the end, I am suppose to feed all these captures to a Report Generator that creates a PPT. 


      Can anyone help me with finding the Tabular Data values? Would it be in a certain file in ANSYS... which I assume it would have to be... but is there any ANSYS API to call for it in my script file?


      THank you very much,


      Douglas99

    • mjmiddle
      Ansys Employee

      Hello Douglas,


      There are tabular data used in multiple ways in Mechanical.  If you want to work with loads, these are described in the Ansys ACT Training for Mechanical in the Ansys Learning Hub. But it sounds like you want to work with result objects, and get the result history data.  For results created as a probe, use the "Sequence" found in the "internalObject". Examples for joint probe:


      probe.InternalObject.SequenceXVector(0)
      probe.InternalObject.SequenceYVector(0)
      probe.InternalObject.SequenceZVector(0)
      probe.InternalObject.SequenceTotalVector(0)


      For other probe types, use dir(probe) to see what kind of "Sequence" objects exist.


      Example for getting tabular values from deformation frequency response for harmonic analysis:


      a = ExtAPI.DataModel.Project.Model.Analyses[0]
      f = a.Solution.AddDeformationFrequencyResponse()
      f.InternalObject.GetAmpAtFrequency(f.MinimumFrequency.Value, 0)
      f.InternalObject.GetPhaseAtFrequency(f.MinimumFrequency.Value)


      For all other result types, you will have to read directly from the GUI entries:


      result.Activate()
      Pane=ExtAPI.UserInterface.GetPane(MechanicalPanelEnum.TabularData)    #This is the "Tabular Data" table at the right
      Con = Pane.ControlUnknown
      # same as Con  = ExtAPI.DataModel.InternalObject["ds"].Graphics.CompositeGrid
      # (1,1) is empty grey box at upper left
      for C in range(1,Con.ColumnsCount+1):
          for R in range(1,Con.RowsCount+1):
              Text = Con.cell(R,C).Text
              if Text!=None:
                  print Text


      Reading directly from the GUI entries means Mechanical must be launched in interactive mode.  It will not work in batch mode.


      Other than trying to read result history tables, you can set the time or result set on a result and evaluate each time to build a history.  This will evaluate from the data in the result file (file.rst), but this is not as efficient as getting data from a result table.

      • Akshay Panchwagh
        Subscriber

        Hello mjmiddle,

        I tried to use a modified version of this script to save the tabular results in a CSV file for a Parameter Set I am evaluating. However, when I try to update the Design Points through Workbench, the script does not work at all. Only when I manually run the simulations through Mechanical does the script store results in a CSV file. I have written the script in a Python Code Object. Can you please let me know what might be going worng? I have been stuck on this issue for many days now. I need to extract these results since I need the temperature values for all the time steps (I am performing transient thermal simuations). 

         

        For your reference, I am sharing the script that I am using for my use-case. The Property Provider has been modified to include the Design Point number as a Parameter.

         

         

        def after_post(this, solution):# Do not edit this line
            """
            Called after post processing.
            Keyword Arguments : 
                this -- the datamodel object instance of the python code object you are currently editing in the tree
                solution -- Solution
            """

            # User Dir

            import os
            import csv
            import wbjn
            UserDir = os.path.dirname(ExtAPI.DataModel.AnalysisList[0].WorkingDir) + "\..\..\..\user_files\\"


            # DPValue as parameter

            DPValue = this.GetCustomPropertyByPath("Parameter/DPValue").Value
            dpn = "DP_"+str(int(DPValue))
            
            def writeCSV(filename, data):

            #Function to write python list to a csv file
                with open(filename, 'wb') as csvfile:

                    spamwriter = csv.writer(csvfile, delimiter=';', quotechar='|', quoting=csv.QUOTE_MINIMAL)

                    for row in data:

                        spamwriter.writerow(row)
                    
            ResultsOfInterest = []

            ResultsOfInterest.append(ExtAPI.DataModel.AnalysisList[0].Solution.Children[1].Name)
            ResultsOfInterest.append(ExtAPI.DataModel.AnalysisList[0].Solution.Children[2].Name)
            ResultsOfInterest.append(ExtAPI.DataModel.AnalysisList[0].Solution.Children[3].Name)
            ResultsOfInterest.append(ExtAPI.DataModel.AnalysisList[0].Solution.Children[4].Name)
            
            cmd = 'returnValue(GetUserFilesDirectory())'
            user_dir = wbjn.ExecuteCommand(ExtAPI, cmd)
            
            solution=ExtAPI.DataModel.AnalysisList[0].Solution

            for j, item in enumerate(solution.Children):

                if item.GetType() == Ansys.ACT.Automation.Mechanical.Results.ThermalResults.TemperatureResult:
            
                    if item.Name in ResultsOfInterest:

                        item.Activate()
                        
                        data=[]

                        del data[:]

                        Pane=ExtAPI.UserInterface.GetPane(MechanicalPanelEnum.TabularData)
                      

                        Con = Pane.ControlUnknown

                        for R in range(1,Con.RowsCount+1):

                            data.append([])

                            for C in range(2,Con.ColumnsCount+1):

                                data[-1].append(Con.cell(R,C).Text)
                                
                            writeCSV(user_dir + "/" + Model.Analyses[0].Name + " - " + item.Name +dpn+ ".csv", data)

            pass

         

        This script was originally written by one Pat Tessaro of Ozen Engineering Inc. I have modified the script which I found on their blogpost. 

Viewing 1 reply thread
  • The topic ‘Tabular Data Extraction’ is closed to new replies.