


{"id":372064,"date":"2024-07-16T08:40:00","date_gmt":"2024-07-16T08:40:00","guid":{"rendered":"https:\/\/innovationspace.ansys.com\/forum\/forums\/topic\/integrate-journal-and-mechanical-script\/"},"modified":"2024-07-16T08:40:00","modified_gmt":"2024-07-16T08:40:00","slug":"integrate-journal-and-mechanical-script","status":"closed","type":"topic","link":"https:\/\/innovationspace.ansys.com\/forum\/forums\/topic\/integrate-journal-and-mechanical-script\/","title":{"rendered":"integrate journal and mechanical script"},"content":{"rendered":"<p>i want to integrate the journal file and mechanical script for automation.&nbsp;<\/p>\n<p>I had some problems.<\/p>\n<p>First. When you run the journal code, the UUID value, which is the material property value, changes and is saved every time, so this value cannot be specified when running a mechanical script.&nbsp;<\/p>\n<p>So to solve this problem, I add&nbsp;<\/p>\n<p>material_name = matl1.Name<br \/>print(&#8220;Material Name: {}&#8221;.format(material_name))<\/p>\n<p>with open(r&#8217;C:\\Users\\hyu3\\Desktop\\bar_example\\material_name.txt&#8217;, &#8216;w&#8217;) as f:<br \/>&nbsp; &nbsp; f.write(material_name)<\/p>\n<p>&nbsp;<\/p>\n<p>this code to journal file , and fix the mechanical script code like this&nbsp;<\/p>\n<p>#region UI Action<br \/>with Transaction(True):<br \/>&nbsp; &nbsp; body_21 = DataModel.GetObjectById(21)<br \/>&nbsp; &nbsp; body_21.Material = material_name<br \/>#endregion<\/p>\n<p>Second. I want to integrate this processes in one python code.<\/p>\n<p>Can you give me any advice or guide line?&nbsp;<\/p>\n<p>here is my full code about the journal file<\/p>\n<p># encoding: utf-8<br \/># 2024 R1<br \/>SetScriptVersion(Version=&#8221;24.1.144&#8243;)<\/p>\n<p># Static Structural&nbsp;<br \/>template1 = GetTemplate(<br \/>&nbsp; &nbsp; TemplateName=&#8221;Static Structural&#8221;,<br \/>&nbsp; &nbsp; Solver=&#8221;ANSYS&#8221;)<br \/>system1 = template1.CreateSystem()<\/p>\n<p>favorites1 = EngData.LoadFavoriteItems()<\/p>\n<p>library1 = EngData.OpenLibrary(<br \/>&nbsp; &nbsp; Name=&#8221;General Materials&#8221;,<br \/>&nbsp; &nbsp; Source=&#8221;General_Materials.xml&#8221;)<br \/>engineeringData1 = system1.GetContainer(ComponentName=&#8221;Engineering Data&#8221;)<br \/>matl1 = engineeringData1.ImportMaterial(<br \/>&nbsp; &nbsp; Name=&#8221;Stainless Steel&#8221;,<br \/>&nbsp; &nbsp; Source=&#8221;General_Materials.xml&#8221;)<\/p>\n<p>EngData.EnableFilter(Enable=False)<br \/>EngData.EnableFilter()<\/p>\n<p>material_name = matl1.Name<br \/>print(&#8220;Material Name: {}&#8221;.format(material_name))<\/p>\n<p>with open(r&#8217;C:\\Users\\hyu3\\Desktop\\bar_example\\material_name.txt&#8217;, &#8216;w&#8217;) as f:<br \/>&nbsp; &nbsp; f.write(material_name)<\/p>\n<p>geometry1 = system1.GetContainer(ComponentName=&#8221;Geometry&#8221;)<br \/>geometry1.SetFile(FilePath=&#8221;C:\/Users\/hyu3\/Desktop\/bar_example\/bar.stp&#8221;)<\/p>\n<p>modelComponent1 = system1.GetComponent(Name=&#8221;Model&#8221;)<br \/>modelComponent1.Refresh()<br \/>model1 = system1.GetContainer(ComponentName=&#8221;Model&#8221;)<br \/>model1.Edit()<\/p>\n<p>&nbsp;<\/p>\n<p>And here is my mechanical script file code&nbsp;<\/p>\n<p># NOTE: All workflows will not be recorded, as recording is under development.<\/p>\n<p># Set the unit system<br \/>ExtAPI.Application.ActiveUnitSystem = MechanicalUnitSystem.StandardNMM<\/p>\n<p>with open(r&#8217;C:\\Users\\hyu3\\Desktop\\bar_example\\material_name.txt&#8217;, &#8216;r&#8217;) as f:<br \/>&nbsp; &nbsp; material_name = f.read().strip()<\/p>\n<p>#region UI Action<br \/>with Transaction(True):<br \/>&nbsp; &nbsp; body_21 = DataModel.GetObjectById(21)<br \/>&nbsp; &nbsp; body_21.Material = material_name<br \/>#endregion<\/p>\n<p>#region Details View Action<br \/>body_21.NonlinearEffects = False<br \/>#endregion<\/p>\n<p>#region Details View Action<br \/>body_21.ThermalStrainEffects = False<br \/>#endregion<\/p>\n<p>#region Context Menu Action<br \/>mesh_16 = Model.Mesh<br \/>sizing_39 = mesh_16.AddSizing()<br \/>#endregion<\/p>\n<p>#region Details View Action<br \/>selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)<br \/>selection.Ids = [30]<br \/>sizing_39.Location = selection<br \/>#endregion<\/p>\n<p>#region Details View Action<br \/>sizing_39.ElementSize = Quantity(5, &#8220;mm&#8221;)<br \/>#endregion<\/p>\n<p>#region Context Menu Action<br \/>analysis_25 = DataModel.GetObjectById(25)<br \/>force_41 = analysis_25.AddForce()<br \/>#endregion<\/p>\n<p>#region Details View Action<br \/>selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)<br \/>selection.Ids = [26]<br \/>force_41.Location = selection<br \/>#endregion<\/p>\n<p>#region Details View Action<br \/>force_41.DefineBy = LoadDefineBy.Components<br \/>#endregion<\/p>\n<p>#region Details View Action<br \/>force_41.YComponent.Output.SetDiscreteValue(0, Quantity(-1000, &#8220;N&#8221;))<br \/>#endregion<\/p>\n<p>#region Context Menu Action<br \/>fixed_support_43 = analysis_25.AddFixedSupport()<br \/>#endregion<\/p>\n<p>#region Details View Action<br \/>selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)<br \/>selection.Ids = [28]<br \/>fixed_support_43.Location = selection<br \/>#endregion<\/p>\n<p>#region Context Menu Action<br \/>solution_26 = DataModel.GetObjectById(26)<br \/>total_deformation_45 = solution_26.AddTotalDeformation()<br \/>#endregion<\/p>\n<p>#region Context Menu Action<br \/>equivalent_elastic_strain_rst46 = solution_26.AddEquivalentElasticStrainRST()<br \/>#endregion<\/p>\n<p>#region Context Menu Action<br \/>equivalent_stress_47 = solution_26.AddEquivalentStress()<br \/>#endregion<\/p>\n<p>&nbsp;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/innovationspace.ansys.com\/forum\/wp-content\/uploads\/sites\/2\/2024\/07\/16-07-2024-1721119072-mceclip0.png\"><\/p>\n","protected":false},"template":"","class_list":["post-372064","topic","type-topic","status-closed","hentry"],"aioseo_notices":[],"acf":[],"custom_fields":[{"0":{"_bbp_subscription":["79070","200"],"_bbp_author_ip":["166.104.168.180"]," _bbp_last_reply_id":["0"]," _bbp_likes_count":["0"],"_btv_view_count":["242"],"_bbp_topic_status":["unanswered"],"_bbp_topic_id":["372064"],"_bbp_forum_id":["27791"],"_bbp_engagement":["200","79070"],"_bbp_voice_count":["2"],"_bbp_reply_count":["1"],"_bbp_last_reply_id":["373230"],"_bbp_last_active_id":["373230"],"_bbp_last_active_time":["2024-07-23 12:44:38"]},"test":"tigers1227hanyang-ac-kr"}],"_links":{"self":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/topics\/372064","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\/372064\/revisions"}],"wp:attachment":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/media?parent=372064"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}