General Mechanical

General Mechanical

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

Python-Script to Export all Children of a Solution Tree

    • FS
      Subscriber

      I have a transient thermal model which solves at a number of times steps, the number may vary from simulation conditions. The results at each time step are stored in a solution folder.

      For postprocessing I want to export the (in this case) temperature at each time step. I have created the following script. However it requires to enter the number of children manually. How can I determine the number of children, such as to remain the script untouched independent of the solution. BTW:

      r1.Children 

      does not work.

      Script:

      '''
      Export all children in solution folder 'Temperature'
      '''

      import os

      analysis=ExtAPI.DataModel.Project.Model.Analyses[0]
      locationToExport = analysis.WorkingDir
      # Enter number time steps
      nsteps = 20
      steps = list(range(2,nsteps+2))

      for i in steps:
          resultsName = 'Temperature '+ str(i)
          fileName = resultsName + '.txt'
          fileToExport = os.path.join(locationToExport,fileName)
          r1=ExtAPI.DataModel.GetObjectsByName(resultsName)[0]
          r1.ExportToTextFile(fileToExport)
Viewing 0 reply threads
  • You must be logged in to reply to this topic.