Extracting plots in batch mode from workbench project page

Pernelle Marone-Hitz
Pernelle Marone-Hitz Member, Moderator, Employee Posts: 871
100 Answers 500 Comments 250 Likes First Anniversary
✭✭✭✭

Extracting plots in batch mode from workbench project page

Tagged:

Answers

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 871
    100 Answers 500 Comments 250 Likes First Anniversary
    ✭✭✭✭
    edited December 2023

    Please adapt the below script.
    We need to use "model1.Edit(Hidden=True)" to achieved

    # Export plots
    cmd= """
    import os
    import time
    def TakeScreenshot(args):
        #Take screenshot of object
        imagePath = args[0]
        imageName = args[1]
        setting2d = Ansys.Mechanical.Graphics.GraphicsImageExportSettings()
        setting2d.Resolution = GraphicsResolutionType.HighResolution
        setting2d.Width = 838
        setting2d.Height = 392
        setting2d.Background = GraphicsBackgroundType.White
        setting2d.CurrentGraphicsDisplay = False
        totalPath = os.path.join(imagePath, imageName) + '.png'
        ExtAPI.Graphics.ExportImage(totalPath, GraphicsImageExportFormat.PNG,
                                    setting2d)   
    
    def OnButtonClickScreenshot(arg):
        #Action when button is clicked (need to separate process in UIThread) 
        imagePath = "D:\Data"
        imageName = arg
        ExtAPI.Application.InvokeUIThread(TakeScreenshot, [imagePath, imageName])
    
    results=Model.Analyses[0].Solution.GetChildren(DataModelObjectCategory.Result,True)
    for result in results:
        result.Activate()
        Graphics.Camera.SetSpecificViewOrientation(ViewOrientationType.Iso)
        Graphics.Camera.SetFit()
        imgName=result.Name
        OnButtonClickScreenshot(imgName)
    """
    
    system1 = GetSystem(Name="SYS")
    model1 = system1.GetContainer(ComponentName="Model")
    model1.Edit(Hidden=True)
    model1.SendCommand(Language="Python", Command=cmd)