How can I insert an image or a figure in the Mechanical Tree, through ACT?
Pernelle Marone-Hitz
Member, Moderator, Employee Posts: 871
✭✭✭✭
How can I insert an image or a figure in the Mechanical Tree, through ACT ?
Tagged:
0
Answers
-
To create a figure object (that can be further manipulated, rotated for example), one can use AddFigure() method, for example :
ExtAPI.DataModel.Tree.ActiveObjects[0].AddFigure()
There is not similar function to create an image, but one can use the following workaround :
- Create a screenshot through ExportScreenToImage() method
- Insert this image in the Mechanical tree through AddImage() method.
Here is a script example :
ImgPath= r"E:\test.png" ExtAPI.Graphics.ExportScreenToImage(ImgPath) IntObj = ExtAPI.DataModel.Tree.ActiveObjects[0].InternalObject Img = IntObj.AddImage() Img.SourceType = 1 Img.ImagePath = ImgPath
2 -
You can also create and add a figure to the tree (solution) from a Python Code (object) if you use the Cpython engine. You can create a Python Code object and set it to after Post, set the Engine Type to Cpython and paste the script below to generate a figure in the tree.
def after_post(this, solution):# Do not edit this line import matplotlib.pyplot as plt import os plt.plot([1,2,3,4,5],[5,10,15,20,25],color='red') plt.ylabel('hello [unit]') plt.xlabel('kitty [unit]') plt.grid() wd = solution.Parent.WorkingDir myPath = os.path.join(wd,'myFig.png') plt.savefig(myPath) image = solution.AddImage(myPath) pass
2