Export Figures

Goal

The following script enables you to automatically export any Figures included in your analysis to a specified folder. Figures are often useful for examining results.

Code

# Export to jpeg files a selection of figures from the tree
# Pictures are stored in the corresponding analysis folder
# Created by P. Thieffry
# Last update: 2021/04/14

clr.AddReference("Ans.UI.Toolkit.Base")
clr.AddReference("Ans.UI.Toolkit")
from Ansys.UI.Toolkit import *

figures=ExtAPI.DataModel.Tree.ActiveObjects

if (figures.Count == 0): 
    mess_line1 = 'Please select at least one figure'
    MessageBox.Show(mess_line1)
    pass

if (figures[0].GetType()!= Ansys.ACT.Automation.Mechanical.Figure): 
    mess_line1 = 'Please select figure(s)'
    MessageBox.Show(mess_line1)
    pass

import wbjn
cmd = 'returnValue(GetUserFilesDirectory())'
user_dir = wbjn.ExecuteCommand(ExtAPI,cmd)

for fig in figures:
    if fig.GetType() != Ansys.ACT.Automation.Mechanical.Figure:
         continue

    ExtAPI.DataModel.Tree.Activate(fig)
    anWD=ExtAPI.DataModel.AnalysisById(0).WorkingDir
    filename=user_dir+'\\'+'Figure - '+fig.Parent.Name+'.jpg'
    ExtAPI.Graphics.ExportImage(filename)
    msg = Ansys.Mechanical.Application.Message('Figure for '+fig.Parent.Name+' stored in folder '+user_dir, MessageSeverityType.Info)
    ExtAPI.Application.Messages.Add(msg)