Graphics.Camera.SetFit()

cobonz
cobonz Member Posts: 8
First Comment
**

I have a code where I use the SetFit() command. Unfortunately it seems that in the batch mode (closed mechanical) it does not work probably often the images generated are not zoomed in or cut half. Is there an work around.

                for view in views:
                    if m % 3 == 0:
                            html_content += '  <tr>\n'
                    m = m+1
                    Graphics.Camera.SetSpecificViewOrientation(view)
                    ExtAPI.Graphics.Camera.SetFit()
                    a= StressResult.AddFigure()
                    a.Name = a.Parent.Parent.Name+' '+name+' '+str(view)
                    output_image_path = r"R:\delete_tmp\{0} {1} {2}.png".format(a.Parent.Parent.Name,name,str(view))
                    Graphics.ExportImage(output_image_path, GraphicsImageExportFormat.PNG, image_settings)
                    html_content += '<td><img src="{}" alt="Image"></td>\n'.format(output_image_path)
                    FigureList.append(a)

I also tried
import context_menu
context_menu.SetFit() which did not work either.

Answers

  • Landon Mitchell Kanner
    Landon Mitchell Kanner Member, Employee Posts: 290
    100 Comments 25 Answers 25 Likes Photogenic
    ✭✭✭✭
    edited December 2023

  • cobonz
    cobonz Member Posts: 8
    First Comment
    **

    I have no permission to the link

  • Landon Mitchell Kanner
    Landon Mitchell Kanner Member, Employee Posts: 290
    100 Comments 25 Answers 25 Likes Photogenic
    ✭✭✭✭
    edited December 2023

    Sorry, I have removed the link and copied a summary of the conversation here:

    With "Interactive=False" most of the graphics-related APIs are not available.

    The best possibility would be to use the hidden mode "Hidden=True" that acts like a batch mode but still loads those graphics APIs.

  • cobonz
    cobonz Member Posts: 8
    First Comment
    **

    I reckon I do not understand much.

    Interacitve = False is if I close the GUI? and its currently basically not possible to use the camera without the GUI correctly

    Hidden = True --> you mean that I could run the script in the GUI but the GUI is not updating until the script is done?

  • Landon Mitchell Kanner
    Landon Mitchell Kanner Member, Employee Posts: 290
    100 Comments 25 Answers 25 Likes Photogenic
    ✭✭✭✭

    Interactive = False means there will be no graphics operations
    Hidden = True means graphics operations will be running but not displayed. (The GUI will be hidden)

    How are you launching Mechanical and running your script?

  • cobonz
    cobonz Member Posts: 8
    First Comment
    **

    I open mechanical through workbench.

    I inserted a pythoncode under solution as After Post command and "solve" the python code.

    I could also run the script with the script editor, but I wish I could run it in the batch mode. Therefore, I inserted the After Post command which works fine beside the camera operation SetFit()

  • Landon Mitchell Kanner
    Landon Mitchell Kanner Member, Employee Posts: 290
    100 Comments 25 Answers 25 Likes Photogenic
    ✭✭✭✭

    When you open Mechanical through Workbench use Hidden = True instead of Interactive = False

  • cobonz
    cobonz Member Posts: 8
    First Comment
    **

    Hi Landon,
    a late call back.
    I think what I lacked to describe back in December was my wished work progress.

    What my script is currently doing is that it automates some of the post processing and a report with pictures (where the zoom does not work correctly in batch mode).

    What I tried with the phyton post command under the solution branch is that if I close mechanical and press update project in workbench the project is sent for example over night to a cluster and the solution will be optained. After the solution is done Ansys will retrieve the results and then excute the post command. The next morning when I start the PC I do not have to launch the phyton code it will already be executed and I have a report at hand.
    So the way I want to run it is just click on update project in Ansys Workbench. Problem was/is that the picture and zoom function will create some strange views instead of the expected ones.

  • Landon Mitchell Kanner
    Landon Mitchell Kanner Member, Employee Posts: 290
    100 Comments 25 Answers 25 Likes Photogenic
    ✭✭✭✭

    This sounds like a bug. I recommend you contact your Ansys Tech Support provider.