Graphics.Camera.SetFit()

cobonz
cobonz Member Posts: 6
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: 177
    First Answer First Comment 5 Likes First Anniversary
    edited December 2023

  • cobonz
    cobonz Member Posts: 6
    First Comment

    I have no permission to the link

  • Landon Mitchell Kanner
    Landon Mitchell Kanner Member, Employee Posts: 177
    First Answer First Comment 5 Likes First Anniversary
    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: 6
    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: 177
    First Answer First Comment 5 Likes First Anniversary

    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: 6
    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: 177
    First Answer First Comment 5 Likes First Anniversary

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