How do I export pictures for multiple design points?

Member, Moderator, Employee Posts: 108
25 Answers Second Anniversary 10 Comments 25 Likes
✭✭✭✭
edited June 2023 in Structures

I am running a simulation for which I create figures for various results. I want to export them for each design point. How can I do this?

Welcome!

It looks like you're new here. Sign in or register to get started.

Comments

  • Member, Moderator, Employee Posts: 108
    25 Answers Second Anniversary 10 Comments 25 Likes
    ✭✭✭✭

    Here's a sample code to use in a Python Code object. For this to work, you will have to use version 23.1 and above as picture export in batch mode did not work in earlier versions.

    Small bonus: you'll see how to retrieve the design point number and the user_files folder without the need for executing a script at project page level.


    1. def after_post(this, solution):# Do not edit this line
    2.   """
    3.   Called after post processing.
    4.   Keyword Arguments : 
    5.     this -- the datamodel object instance of the python code object you are currently editing in the tree
    6.     solution -- Solution
    7.   """
    8.  
    9.  
    10.   figures=ExtAPI.DataModel.GetObjectsByType(DataModelObjectCategory.Figure)
    11.    
    12.    
    13.   import os
    14.   cmd = 'returnValue(GetUserFilesDirectory())'
    15.    
    16.   wd=this.Parent.Parent.WorkingDir
    17.   dp=wd.split('\\')[-4]
    18.   user_dir=os.path.join(wd,'..\\..\\..\\user_files')
    19.    
    20.   for fig in figures:
    21.  
    22.      
    23.     ExtAPI.DataModel.Tree.Activate(fig)
    24.     filename=user_dir+'\\'+'Figure - '+fig.Parent.Name+'_'+dp+'.jpg'
    25.     ExtAPI.Graphics.ExportImage(filename)


  • Member Posts: 1
    Name Dropper First Comment
    **

    Hello @Pierre Thieffry ,

    thank you for the post, it is really helpful!

    I am trying to do some modifications on the legend text, to increase it.

    I've tried something like this based on the documentation which I found on the web, but it is not working:

    ExtAPI.Graphics.ExportImage(filename,  GraphicsImageExportFormat('png'), GraphicsImageExportSettings.FontMagnification(1.3))


    Can you help me please with this ?

  • Member, Employee Posts: 249
    50 Answers 100 Comments 100 Likes Second Anniversary
    ✭✭✭✭
    edited January 2024

    Figures in this example mean static generated images and not the dynamic Ansys plots. .AddFigure() will add the figure below any selected result.

    I have an adaptation that will generate the image if it doesn't already exist and write that image to file:

    1. def after_post(this, solution):# Do not edit this line
    2. """
    3. Called after post processing.
    4. Keyword Arguments :
    5. this -- the datamodel object instance of the python code object you are currently editing in the tree
    6. solution -- Solution
    7. """
    8. import wbjn
    9. import os
    10.  
    11. dpn = wbjn.ExecuteCommand(ExtAPI,"returnValue(a+Parameters.GetActiveDesignPoint().Name)",a="DP")
    12. user_dir = wbjn.ExecuteCommand(ExtAPI,"returnValue(GetUserFilesDirectory())")
    13.  
    14. results = ExtAPI.DataModel.GetObjectsByType(DataModelObjectCategory.Result)
    15.  
    16. for result in results:
    17. ExtAPI.Log.WriteMessage('bob')
    18. children = result.Children
    19. if not any(i for i in children if 'Figure' in i.ToString()):
    20. children = result.AddFigure()
    21. elif 'Figure' in children[0].ToString():
    22. children = children[0]
    23. children.Activate()
    24. filename = os.path.join(user_dir,'Figure - '+children.Parent.Name+'_'+dpn+'.jpg' )
    25. ExtAPI.Log.WriteMessage(filename)
    26. ExtAPI.Graphics.ExportImage(filename,GraphicsImageExportFormat.JPG)

Welcome!

It looks like you're new here. Sign in or register to get started.