-
-
August 23, 2022 at 8:51 am
ianv
SubscriberI am trying to export snapshots of Von-Mises stress results with some Python code:
Model=ExtAPI.DataModel.Project.Model
result=Model.Analyses[0].Solution.Children[1]
ExtAPI.DataModel.Tree.Activate(result)
Graphics.Camera.SetSpecificViewOrientation(ViewOrientationType.Front)
Graphics.Camera.SetFit()
directory = "C:\\Users\\ianve\\Desktop\\WORK\\CURRENT\\Tridem\\Results"
file_stress_side = directory + "\\stress_side.jpg"
file_stress_top = directory + "\\stress_top.jpg"
file_stress_bottom = directory + "\\stress_bottom.jpg"
file_stress_iso = directory + "\\stress_iso.jpg"
setting2d = Ansys.Mechanical.Graphics.GraphicsImageExportSettings()
setting2d.Width = 1920
setting2d.Height = 1080
setting2d.Background = GraphicsBackgroundType.White
setting2d.CurrentGraphicsDisplay = False
Graphics.ExportImage(file_stress_side, GraphicsImageExportFormat.JPG, setting2d)
Graphics.Camera.SetSpecificViewOrientation(ViewOrientationType.Top)
Graphics.Camera.SetFit()
Graphics.ExportImage(file_stress_top, GraphicsImageExportFormat.JPG, setting2d)
Graphics.Camera.SetSpecificViewOrientation(ViewOrientationType.Bottom)
Graphics.Camera.SetFit()
Graphics.ExportImage(file_stress_bottom, GraphicsImageExportFormat.JPG, setting2d)
Graphics.Camera.SetSpecificViewOrientation(ViewOrientationType.Iso)
Graphics.Camera.SetFit()
Graphics.ExportImage(file_stress_iso, GraphicsImageExportFormat.JPG, setting2d)The problem I encounter is every time I solve the system from Workbench, the snapshots are not saved. When I export the stress results as a text file with:
top_result = DataModel.GetObjectsByName("Top")[0]
top_result.ExportToTextFile("C:\\Users\\ianve\\Desktop\\WORK\\CURRENT\\Tridem\\Results\\top.txt")
bot_result = DataModel.GetObjectsByName("Bottom")[0]
bot_result.ExportToTextFile("C:\\Users\\ianve\\Desktop\\WORK\\CURRENT\\Tridem\\Results\\bot.txt")
side_result = DataModel.GetObjectsByName("Side")[0]
side_result.ExportToTextFile("C:\\Users\\ianve\\Desktop\\WORK\\CURRENT\\Tridem\\Results\\side.txt")the code executes every time. When I solve from Mechanical itself, the snapshots are created and saved. How can I fix this or work around it?
-
August 23, 2022 at 9:53 am
Erik Kostson
Ansys EmployeeFirst of all try it in 2022 R2.
Now if it does not work then the below works in 2022 R2 (not on previous versions):
One way to do this is to run a python script from workbench (wb) – go to workbench->file->scripting->run script file … and choose the script (say saveimage.py) that contains say the following sample code to save some results to text file (you need to change it as needed, and it is outisde the help I can provide to adjust it to your needs – perhaps other users can help with that if needed – the below assumes you have only on system in the project, so you might need to account for that – to learn more about wb scripting you can record them in wb):
SetScriptVersion(Version=”22.2.192″)
Update()
cmd=”'
res=ExtAPI.DataModel.GetObjectsByName(“Total Deformation”)[0]
ExtAPI.DataModel.Tree.Activate(res)
res.ExportToTextFile(“D:/OTHER/sunbatch/testexpfile.txt”)
graphics=Graphics.ExportImage(“D:/OTHER/sunbatch/testexpfile.jpeg”)
”'
system1 = GetSystem(Name=”SYS”)
model1 = system1.GetContainer(ComponentName=”Model”)
model1.Edit(Interactive=False)
model1.SendCommand(Language=”Python”, Command=cmd)-
September 5, 2022 at 6:20 pm
peteroznewman
SubscriberHi Erik,
I tried your Python script in Workbench 2022R2. This was my first time using a Python script in Workbench. I copied the lines from your post and pasted them into a text editor to save the script. Unfortunately, something (this website?) converted the ASCII character ” into a Non-ASCII character ” which causes Iron Python to throw an error.
I went through the script and replaced all the Non-ASCII characters such as shown on the first line with ASCII characters such as shown on the second line, but ended up with other errors.
I was just curious to see Python running in Workbench and may learn it at some point time, but thought I would reply in case someone else tried your code and found this problem. I expect if the formatting in the reply is set to Preformatted instead of Paragraph, it might prevent the characters from being changed.
Regards,
Peter
-
-
August 25, 2022 at 6:03 am
ianv
SubscriberThank you for the response. I am using 2022 R1 at the moment and the export to textfile works without any problems but I want to export snapshots of the stress plots in Mechanical rather than text files of nodal results. Reason being I do not want to do post processing in Python. I have done it before, but it is a lot of extra work for something that is already being done in ANSYS automatically.
-
- You must be logged in to reply to this topic.

Earth Rescue – An Ansys Online Series
The climate crisis is here. But so is the human ingenuity to fight it. Earth Rescue reveals what visionary companies are doing today to engineer radical new ideas in the fight against climate change. Click here to watch the first episode.

Ansys Blog
Subscribe to the Ansys Blog to get great new content about the power of simulation delivered right to your email on a weekly basis. With content from Ansys experts, partners and customers you will learn about product development advances, thought leadership and trends and tips to better use Ansys tools. Sign up here.
- Saving & sharing of Working project files in .wbpz format
- An Unknown error occurred during solution. Check the Solver Output…..
- Understanding Force Convergence Solution Output
- Solver Pivot Warning in Beam Element Model
- Colors and Mesh Display
- How to calculate the residual stress on a coating by Vickers indentation?
- whether have the difference between using contact and target bodies
- What is the difference between bonded contact region and fixed joint
- The solver engine was unable to converge on a solution for the nonlinear problem as constrained.
- User manual
-
2656
-
2116
-
1339
-
1118
-
461
© 2023 Copyright ANSYS, Inc. All rights reserved.