-
-
July 16, 2024 at 8:40 amtigers1227Subscriber
i want to integrate the journal file and mechanical script for automation.Â
I had some problems.
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.Â
So to solve this problem, I addÂ
material_name = matl1.Name
print("Material Name: {}".format(material_name))
with open(r'C:\Users\hyu3\Desktop\bar_example\material_name.txt', 'w') as f:
  f.write(material_name)Â
this code to journal file , and fix the mechanical script code like thisÂ
#region UI Action
with Transaction(True):
  body_21 = DataModel.GetObjectById(21)
  body_21.Material = material_name
#endregionSecond. I want to integrate this processes in one python code.
Can you give me any advice or guide line?Â
here is my full code about the journal file
# encoding: utf-8
# 2024 R1
SetScriptVersion(Version="24.1.144")# Static StructuralÂ
template1 = GetTemplate(
  TemplateName="Static Structural",
  Solver="ANSYS")
system1 = template1.CreateSystem()
favorites1 = EngData.LoadFavoriteItems()
library1 = EngData.OpenLibrary(
  Name="General Materials",
  Source="General_Materials.xml")
engineeringData1 = system1.GetContainer(ComponentName="Engineering Data")
matl1 = engineeringData1.ImportMaterial(
  Name="Stainless Steel",
  Source="General_Materials.xml")
EngData.EnableFilter(Enable=False)
EngData.EnableFilter()
material_name = matl1.Name
print("Material Name: {}".format(material_name))
with open(r'C:\Users\hyu3\Desktop\bar_example\material_name.txt', 'w') as f:
  f.write(material_name)
geometry1 = system1.GetContainer(ComponentName="Geometry")
geometry1.SetFile(FilePath="C:/Users/hyu3/Desktop/bar_example/bar.stp")
modelComponent1 = system1.GetComponent(Name="Model")
modelComponent1.Refresh()
model1 = system1.GetContainer(ComponentName="Model")
model1.Edit()Â
And here is my mechanical script file codeÂ
# NOTE: All workflows will not be recorded, as recording is under development.
# Set the unit system
ExtAPI.Application.ActiveUnitSystem = MechanicalUnitSystem.StandardNMM
with open(r'C:\Users\hyu3\Desktop\bar_example\material_name.txt', 'r') as f:
  material_name = f.read().strip()#region UI Action
with Transaction(True):
  body_21 = DataModel.GetObjectById(21)
  body_21.Material = material_name
#endregion#region Details View Action
body_21.NonlinearEffects = False
#endregion#region Details View Action
body_21.ThermalStrainEffects = False
#endregion#region Context Menu Action
mesh_16 = Model.Mesh
sizing_39 = mesh_16.AddSizing()
#endregion#region Details View Action
selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
selection.Ids = [30]
sizing_39.Location = selection
#endregion#region Details View Action
sizing_39.ElementSize = Quantity(5, "mm")
#endregion#region Context Menu Action
analysis_25 = DataModel.GetObjectById(25)
force_41 = analysis_25.AddForce()
#endregion#region Details View Action
selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
selection.Ids = [26]
force_41.Location = selection
#endregion#region Details View Action
force_41.DefineBy = LoadDefineBy.Components
#endregion#region Details View Action
force_41.YComponent.Output.SetDiscreteValue(0, Quantity(-1000, "N"))
#endregion#region Context Menu Action
fixed_support_43 = analysis_25.AddFixedSupport()
#endregion#region Details View Action
selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
selection.Ids = [28]
fixed_support_43.Location = selection
#endregion#region Context Menu Action
solution_26 = DataModel.GetObjectById(26)
total_deformation_45 = solution_26.AddTotalDeformation()
#endregion#region Context Menu Action
equivalent_elastic_strain_rst46 = solution_26.AddEquivalentElasticStrainRST()
#endregion#region Context Menu Action
equivalent_stress_47 = solution_26.AddEquivalentStress()
#endregionÂ
-
July 23, 2024 at 12:44 pmAniketForum Moderator
Hello,
You can use something like:
Model.Geometry.Children[0].Children[0].Material="Structural Steel"
instead of using journal code.-Aniket
-
- The topic ‘integrate journal and mechanical script’ is closed to new replies.
-
1882
-
802
-
599
-
591
-
366
© 2025 Copyright ANSYS, Inc. All rights reserved.