A button to save a screenshot of the selected element in the Tree
Hi,
I made a custom button to save screenshots from my analysis:
image_settings = Ansys.Mechanical.Graphics.GraphicsImageExportSettings() image_settings.CurrentGraphicsDisplay = True file_name = Tree.FirstActiveObject.GetType().Name + '.png' Graphics.ExportImage('C:/.../.../files/'+file_name, GraphicsImageExportFormat.PNG, image_settings)
All works fine except that I need a custom name of the final file to be equal to the actual name of the element in tree I select.
For instance if I have several Equivalent Stress results, they all will be overwritten in one file: EquivalentStress.png based on this line:file_name = Tree.FirstActiveObject.GetType().Name + '.png'
Answers
-
Hi @sombodyfromtheworld , try:
Tree.FirstActiveObject.Name
This will get you the display name of the object selected in Mechanical.
What you retrieve withTree.FirstActiveObject.GetType().Name
is the type of result (stress, deformation, etc.), not the result name.
This post could also be useful if you want to export several results in just one click:
https://discuss.ansys.com/discussion/726/export-screenshot-of-result-for-each-result-in-the-tree?utm_source=community-search&utm_medium=organic-search&utm_term=export1 -
@sombodyfromtheworld ,
keep in mind you can also use the Obj.ObjectId property to return a unique integer. You can then use this as part of the filename to ensure it is unique. Also keep in mind mechanical allows any characters in the object names and some are not able to be part of a file path. You will get an error and should modify those characters to file-safe characters to your liking. Or bypass the object name concept and simply use the object Id as an identifier/unique name.2 -
Thank you @Pernelle Marone-Hitz and @Mike.Thompson for tips and recommendations
0