How save results picture with a script

PierreLCV
PierreLCV Member Posts: 35
10 Comments Name Dropper
**
edited June 5 in Structures

Hello everyone,
I am currently working on a 2D FEA thermal simulation on Ansys Mechanical for which I am using a script as I have a lot of different boundary conditions to use. I have field temperature I would like to save at each iteration of my script, see just after :

This last field being the result of the user defined expression.

The question is then simple, how save this picture at each iteration of my script ? I know that I can save the current image (I mean the one which appears at the screen) with the following command but how specify that I want to save the picture of the user defined result ?
Ansys.Mechanical.Graphics.GraphicsImageExportSettings().CurrentGraphicsDisplay

Thank you !
Pierre

Comments

  • PierreLCV
    PierreLCV Member Posts: 35
    10 Comments Name Dropper
    **

    Hello,
    No idea ? I don't think I'm the only one who needs to save the results of my simulations?

    Thank you,
    Pierre

  • Erik Kostson
    Erik Kostson Member, Employee Posts: 210
    50 Answers 100 Comments 25 Likes Name Dropper
    ✭✭✭✭
    edited June 7

    Hi

    I hope the below does what you want:

    model = ExtAPI.DataModel.Project.Model
    solution=model.Analyses[0].Solution
    user_defined = solution.AddUserDefinedResult()
    
    
    
    user_defined.Expression = r'UY'
    
    
    
    user_defined.EvaluateAllResults()
    
    
    Tree.Activate(user_defined) # activate the result in the tree (so it becomes visible in the window)
    
    image_settings = Ansys.Mechanical.Graphics.GraphicsImageExportSettings()
    image_settings.CurrentGraphicsDisplay = True
    ExtAPI.Graphics.ExportImage('D:/mytestimage.png', GraphicsImageExportFormat.PNG, image_settings)
    

    The user_defined expression can be seen in the ui and the results (top left).


    If one wants instead a screenshot of the whole screen and thus of the whole UI, and not only the model window inside mechanical where the results are, then the below post might be of help:

    https://discuss.ansys.com/discussion/comment/1222#Comment_1222?utm_source=community-search&utm_medium=organic-search&utm_term=save+image

    Thank you and kind regards

    Erik

  • PierreLCV
    PierreLCV Member Posts: 35
    10 Comments Name Dropper
    **

    Dear Erik,
    Thank you very much for your answer ! I will try it and will come back to you :). Sorry for the delay of my answer I do not know how but I have missed your answer.

    Best regards,
    Pierre