


{"id":233531,"date":"2022-08-23T08:51:24","date_gmt":"2022-08-23T08:51:24","guid":{"rendered":"\/forum\/forums\/topic\/python-code-object-not-running-when-static-structural-updates\/"},"modified":"2022-08-23T08:51:24","modified_gmt":"2022-08-23T08:51:24","slug":"python-code-object-not-running-when-static-structural-updates","status":"closed","type":"topic","link":"https:\/\/innovationspace.ansys.com\/forum\/forums\/topic\/python-code-object-not-running-when-static-structural-updates\/","title":{"rendered":"Python Code Object not running when Static Structural updates"},"content":{"rendered":"<p>I am trying to export snapshots of Von-Mises stress results with some Python code:<\/p>\n<p>&nbsp; &nbsp; Model=ExtAPI.DataModel.Project.Model<br \/>&nbsp; &nbsp; result=Model.Analyses[0].Solution.Children[1]<br \/>&nbsp; &nbsp;<br \/>&nbsp; &nbsp; ExtAPI.DataModel.Tree.Activate(result)<br \/>&nbsp; &nbsp;&nbsp;<br \/>&nbsp; &nbsp; Graphics.Camera.SetSpecificViewOrientation(ViewOrientationType.Front)<br \/>&nbsp; &nbsp;&nbsp;<br \/>&nbsp; &nbsp; Graphics.Camera.SetFit()<br \/>&nbsp; &nbsp;&nbsp;<br \/>&nbsp; &nbsp; directory = &#8220;C:\\\\Users\\\\ianve\\\\Desktop\\\\WORK\\\\CURRENT\\\\Tridem\\\\Results&#8221;<br \/>&nbsp; &nbsp;&nbsp;<br \/>&nbsp; &nbsp; file_stress_side = directory + &#8220;\\\\stress_side.jpg&#8221;<br \/>&nbsp; &nbsp; file_stress_top = directory + &#8220;\\\\stress_top.jpg&#8221;<br \/>&nbsp; &nbsp; file_stress_bottom = directory + &#8220;\\\\stress_bottom.jpg&#8221;<br \/>&nbsp; &nbsp; file_stress_iso = directory + &#8220;\\\\stress_iso.jpg&#8221;<br \/>&nbsp; &nbsp;&nbsp;<br \/>&nbsp; &nbsp; setting2d = Ansys.Mechanical.Graphics.GraphicsImageExportSettings()<br \/>&nbsp; &nbsp; setting2d.Width = 1920<br \/>&nbsp; &nbsp; setting2d.Height = 1080<br \/>&nbsp; &nbsp; setting2d.Background = GraphicsBackgroundType.White<br \/>&nbsp; &nbsp; setting2d.CurrentGraphicsDisplay = False<br \/>&nbsp; &nbsp;&nbsp;<br \/>&nbsp; &nbsp; Graphics.ExportImage(file_stress_side, GraphicsImageExportFormat.JPG, setting2d)<br \/>&nbsp; &nbsp;&nbsp;<br \/>&nbsp; &nbsp; Graphics.Camera.SetSpecificViewOrientation(ViewOrientationType.Top)<br \/>&nbsp; &nbsp; Graphics.Camera.SetFit()<br \/>&nbsp; &nbsp; Graphics.ExportImage(file_stress_top, GraphicsImageExportFormat.JPG, setting2d)<br \/>&nbsp; &nbsp;&nbsp;<br \/>&nbsp; &nbsp; Graphics.Camera.SetSpecificViewOrientation(ViewOrientationType.Bottom)<br \/>&nbsp; &nbsp; Graphics.Camera.SetFit()<br \/>&nbsp; &nbsp; Graphics.ExportImage(file_stress_bottom, GraphicsImageExportFormat.JPG, setting2d)<br \/>&nbsp; &nbsp;&nbsp;<br \/>&nbsp; &nbsp; Graphics.Camera.SetSpecificViewOrientation(ViewOrientationType.Iso)<br \/>&nbsp; &nbsp; Graphics.Camera.SetFit()<br \/>&nbsp; &nbsp; Graphics.ExportImage(file_stress_iso, GraphicsImageExportFormat.JPG, setting2d)<\/p>\n<p>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:<\/p>\n<p>&nbsp; &nbsp; top_result = DataModel.GetObjectsByName(&#8220;Top&#8221;)[0]<br \/>&nbsp; &nbsp; top_result.ExportToTextFile(&#8220;C:\\\\Users\\\\ianve\\\\Desktop\\\\WORK\\\\CURRENT\\\\Tridem\\\\Results\\\\top.txt&#8221;)<br \/>&nbsp; &nbsp;&nbsp;<br \/>&nbsp; &nbsp; bot_result = DataModel.GetObjectsByName(&#8220;Bottom&#8221;)[0]<br \/>&nbsp; &nbsp; bot_result.ExportToTextFile(&#8220;C:\\\\Users\\\\ianve\\\\Desktop\\\\WORK\\\\CURRENT\\\\Tridem\\\\Results\\\\bot.txt&#8221;)<br \/>&nbsp; &nbsp;&nbsp;<br \/>&nbsp; &nbsp; side_result = DataModel.GetObjectsByName(&#8220;Side&#8221;)[0]<br \/>&nbsp; &nbsp; side_result.ExportToTextFile(&#8220;C:\\\\Users\\\\ianve\\\\Desktop\\\\WORK\\\\CURRENT\\\\Tridem\\\\Results\\\\side.txt&#8221;)<\/p>\n<p>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?<\/p>\n","protected":false},"template":"","class_list":["post-233531","topic","type-topic","status-closed","hentry","topic-tag-ansysworkbench-ansys-staticstructural","topic-tag-mechanicalworkbench-1","topic-tag-python-scripting"],"aioseo_notices":[],"acf":[],"custom_fields":[{"0":{"_bbp_subscription":["261897","58821","240"],"_bbp_author_ip":["66.198.8.115"]," _bbp_last_reply_id":["0"]," _bbp_likes_count":["0"],"_btv_view_count":["1686"],"_bbp_topic_status":["unanswered"],"_bbp_status":["publish"],"_bbp_topic_id":["233531"],"_bbp_forum_id":["27791"],"_bbp_engagement":["240","58821","261897"],"_bbp_voice_count":["3"],"_bbp_reply_count":["3"],"_bbp_last_reply_id":["234470"],"_bbp_last_active_id":["234470"],"_bbp_last_active_time":["2022-09-05 18:20:02"]},"test":"ianvafrit-co-za"}],"_links":{"self":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/topics\/233531","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/topics"}],"about":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/topics\/233531\/revisions"}],"wp:attachment":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/media?parent=233531"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}