How do I export images with user defined size and user defined Legend Font?
Ayush Kumar
Member, Moderator, Employee Posts: 452
✭✭✭✭
image_settings = Ansys.Mechanical.Graphics.GraphicsImageExportSettings() image_settings.Width = 1600 image_settings.Height = 1500 image_settings.CurrentGraphicsDisplay = True ExtAPI.Graphics.ExportImage(r"\Path\to\test.bmp", GraphicsImageExportFormat.BMP, image_settings)
The above written code exports image with the legend settings user has defined but overwrites the Width and Height to Mechanical default.
Setting image_settings.CurrentGraphicsDisplay = False
exports images with the user defined size but the legend font is then default Mechanical.
I can't find a way to do both. Ideally image_settings.CurrentGraphicsDisplay = True
should not overwrite the image dimensions defined by the user.
Tagged:
0
Answers
-
This is a bug in Mechanical. The only workaround is setting the Legends to desired font and then export the image using the coordinates of the Graphics windows and Bitmap module. Here is the example code.
# Get Graphics Pane coordinates graphics = ExtAPI.UserInterface.GetPane(MechanicalPanelEnum.Graphics) width = graphics.ControlUnknown.Width height = graphics.ControlUnknown.Height Pane = ExtAPI.UserInterface.GetPane(MechanicalPanelEnum.Graphics) Pane.CommandContainer.WindowRect.Left initial_x = Pane.CommandContainer.WindowRect.Left initial_y = Pane.CommandContainer.WindowRect.Top final_x = initial_x + width final_y = initial_y + height # Take screenshot import clr import os import sys clr.AddReference("System.Windows.Forms") clr.AddReference("System.Drawing") from System.Drawing import Bitmap,Graphics,Point,Size from System.Windows.Forms import( Application,Button,Form,FormWindowState, PictureBox,Screen) UserFiles = "D:" Fname = "sample" bmp = Bitmap(1500, 1200) # User defined image size g = Graphics.FromImage(bmp) g.CopyFromScreen(initial_x,initial_y, 0, 0, Size((final_x-initial_x), (final_y-initial_y))) bmp.Save(os.path.join(UserFiles, Fname +".png")) g.Dispose()
6