-
-
August 6, 2024 at 5:29 amBobSubscriber
The script below is a Python code embedded in Ansys Mechanical. After the analysis is performed, the results of each step are intended to be saved into a JSON file.
import json
def after_post(this, solution): # Do not edit this line
  print("post script")
  mesh = DataModel.MeshDataByName(ExtAPI.DataModel.MeshDataNames[0])
  solution = Model.Analyses[0].Solution
  Â
  node_count = mesh.NodeCount
  Â
  aset = Model.Analyses[0].AnalysisSettings
  steps = aset.NumberOfSteps
  Â
  solution = Model.Analyses[0].Solution
  base_dir = "C:\\temp\\"
  Â
  data = {}
  Â
  for step in range(steps):  # steps
    time = aset.GetStepEndTime(step + 1)
  Â
    for obj in solution.Children:
      name = obj.Name
      if name in ["LOCX", "LOCY", "LOCZ", "UX", "UY", "UZ"]:
        obj.DisplayTime = time
        Â
    solution.EvaluateAllResults()
    Â
    timestep_data = []
    Â
    LOCX = DataModel.GetObjectsByName("LOCX")[0].PlotData
    LOCY = DataModel.GetObjectsByName("LOCY")[0].PlotData
    LOCZ = DataModel.GetObjectsByName("LOCZ")[0].PlotData
    UX = DataModel.GetObjectsByName("UX")[0].PlotData
    UY = DataModel.GetObjectsByName("UY")[0].PlotData
    UZ = DataModel.GetObjectsByName("UZ")[0].PlotData
    Â
    for i in range(len(LOCX['Node'])):
      node_data = [
        LOCX["Values"][i],
        LOCY["Values"][i],
        LOCZ["Values"][i],
        UX["Values"][i],
        UY["Values"][i],
        UZ["Values"][i]
      ]
      timestep_data.append(node_data)
    Â
    data[str(step + 1)] = timestep_data
  Â
  sorted_data = {k: data[k] for k in sorted(data)}
  json_file_path = base_dir + "example.json"
  with open(json_file_path, 'w') as json_file:
    json.dump(sorted_data, json_file, indent=4)  print("Data saved to", json_file_path)
  passWhen solving this simulation, the following error occurs. The very strange thing is that when solving the exact same file 10 times, this error occurs about 8 times, while it runs successfully about 2 times. We have not yet identified the cause. Your help is urgently needed!
Â
Error
Error when invoking function 'after_post'.Traceback (most recent call last):
File "", line 30, in after_post
StandardError: Exception has been thrown by the target of an invocation.Traceback (most recent call last):
File "", line 30, in after_post
NotImplementedError: PlotData is not supported for LOCXPython Code "Python Code" (Object ID 721) execution aborted: recursive execution has been detected. This is typically caused by an "update" or "evaluate" command. Please 1) verify the code correctness, and 2) ensure the correct callback is being used.
An error occurred when the post processor attempted to load a specific result. Please review all messages.
-
August 7, 2024 at 5:37 pmmjmiddleAnsys Employee
You shouldn't be using the following in an after_post callback:
solution.EvaluateAllResults()
This would evaluate results again which would run after_post again and get you stuck in an endless loop. The after_post callback is done immediately after all native results are evaluated, so there is no need to call this in your script anyway. All native results will be up-to-date at the time of this after_post callback.
-
- You must be logged in to reply to this topic.
- At least one body has been found to have only 1 element in at least 2 directions
- Error when opening saved Workbench project
- How to apply Compression-only Support?
- Geometric stiffness matrix for solid elements
- Frictional No separation contact
- Image to file in Mechanical is bugged and does not show text
- Timestep range set for animation export
- Script Error Code:800a000d
- Elastic limit load, Elastic-plastic limit load
- Element has excessive thickness change, distortion, is turning inside out
-
1406
-
599
-
591
-
555
-
366
© 2025 Copyright ANSYS, Inc. All rights reserved.