How do I export pictures for multiple design points?

Options
Pierre Thieffry
Pierre Thieffry Member, Moderator, Employee Posts: 98
First Anniversary Ansys Employee Solution Developer Community of Practice Member Photogenic
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?

Comments

  • Pierre Thieffry
    Pierre Thieffry Member, Moderator, Employee Posts: 98
    First Anniversary Ansys Employee Solution Developer Community of Practice Member Photogenic
    Options

    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.


    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
      """
    
    
      figures=ExtAPI.DataModel.GetObjectsByType(DataModelObjectCategory.Figure)
       
       
      import os
      cmd = 'returnValue(GetUserFilesDirectory())'
       
      wd=this.Parent.Parent.WorkingDir
      dp=wd.split('\\')[-4]
      user_dir=os.path.join(wd,'..\\..\\..\\user_files')
       
      for fig in figures:
    
         
        ExtAPI.DataModel.Tree.Activate(fig)
        filename=user_dir+'\\'+'Figure - '+fig.Parent.Name+'_'+dp+'.jpg'
        ExtAPI.Graphics.ExportImage(filename)
    


  • Dima
    Dima Member Posts: 1
    Name Dropper First Comment
    Options

    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 ?

  • M
    M Member, Employee Posts: 230
    First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
    edited January 17
    Options

    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:

    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
        """
        import wbjn
        import os
    
        dpn = wbjn.ExecuteCommand(ExtAPI,"returnValue(a+Parameters.GetActiveDesignPoint().Name)",a="DP")
        user_dir = wbjn.ExecuteCommand(ExtAPI,"returnValue(GetUserFilesDirectory())")
    
        results = ExtAPI.DataModel.GetObjectsByType(DataModelObjectCategory.Result)
    
        for result in results:
            ExtAPI.Log.WriteMessage('bob')
            children = result.Children
            if not any(i for i in children if 'Figure' in i.ToString()):
                children = result.AddFigure()
            elif 'Figure' in children[0].ToString():
                children = children[0]
            children.Activate()
            filename = os.path.join(user_dir,'Figure - '+children.Parent.Name+'_'+dpn+'.jpg' )
            ExtAPI.Log.WriteMessage(filename)
            ExtAPI.Graphics.ExportImage(filename,GraphicsImageExportFormat.JPG)