In this example, using the support files, you will insert a Static Structural analysis object into an undefined Mechanical session and execute a sequence of python journal commands that specify a Joint as Universal, define mesh and boundary and result objects and solve the analysis.
This example begins in the Mechanical application. It requires you to download the following Ansys DesignModeler and python files.
Mechanical_Static_Joint_002_Example.agbd
Mechanical_Static_Joint_002_Example.py
These files are available here.
Procedure
Open Mechanical directly without importing a geometry or specifying an analysis type. This can be done through Start Menu.
From the Analysis drop-down menu of the Insert group on the Home tab, insert a system into the tree.
Select the Geometry object and select the Attach Geometry option from the Geometry group on the Geometry Context tab. Navigate to the proper folder location and select Mechanical_Static_Joint_002_Example.agbd.
Select the Automation tab and select the Scripting option to open the Mechanical Scripting pane.
Select the Open Script option (
) from the Editor toolbar. Navigate to the proper folder location and select Mechanical_Static_Joint_002_Example.py.
Select the Run Script option (
) from the Editor toolbar.
Scripts Illustrated
In this example, the python file automatically performs the following actions:
#======================================================================================================================= # ACT Mechanical API Example for General Joint as Translational # Python Script Scenarios: # 1. Set up the Unit Systems # 2. Set up the Tree Object Items # 3. Define Named Selections # 4. Define General Joint as Translational # 5. Define Mesh Settings # 6. Insert Displacement BC # 7. Insert Results # 8. Solve and review the results # Reference case: None. Created from scratch. # Reference geometry: ...\DS_Parts\PARA_Parts\LONGBAR.x_t # Script is created by Rahul B Patil. #======================================================================================================================= #Scenario 1 - Set up the Units System ExtAPI.Application.ActiveUnitSystem = MechanicalUnitSystem.StandardMKS #Scenario 2 - Set up the Tree Object Items CONNECTION_GROUP = Model.Connections MESH = Model.Mesh STATIC_STRUCTURAL = Model.Analyses[0] ANALYSIS_SETTINGS = STATIC_STRUCTURAL.Children[0] STATIC_STRUCTURAL_SOLUTION = STATIC_STRUCTURAL.Solution #Scenario 3 - Define Named Selections NS_FIXED_FACE = DataModel.Project.Model.AddNamedSelection() NS_FIXED_FACE.ScopingMethod=GeometryDefineByType.Worksheet NS_FIXED_FACE.Name = "NS_FIXED_FACE" GEN_CRT1 = NS_FIXED_FACE.GenerationCriteria CRT1 = Ansys.ACT.Automation.Mechanical.NamedSelectionCriterion() CRT1.Active=True CRT1.Action=SelectionActionType.Add CRT1.EntityType=SelectionType.GeoFace CRT1.Criterion=SelectionCriterionType.LocationZ CRT1.Operator=SelectionOperatorType.Equal CRT1.Value=Quantity('0.00 [m]') GEN_CRT1.Add(CRT1) NS_FIXED_FACE.Activate() NS_FIXED_FACE.Generate() NS_BC_FACE = DataModel.Project.Model.AddNamedSelection() NS_BC_FACE.ScopingMethod=GeometryDefineByType.Worksheet NS_BC_FACE.Name = "NS_BC_FACE" GEN_CRT1 = NS_BC_FACE.GenerationCriteria CRT1 = Ansys.ACT.Automation.Mechanical.NamedSelectionCriterion() CRT1.Active=True CRT1.Action=SelectionActionType.Add CRT1.EntityType=SelectionType.GeoFace CRT1.Criterion=SelectionCriterionType.LocationZ CRT1.Operator=SelectionOperatorType.Equal CRT1.Value=Quantity('20.00 [m]') GEN_CRT1.Add(CRT1) NS_BC_FACE.Activate() NS_BC_FACE.Generate() #Scenario 4 - Define General Joint as Translational JOINT_GENERAL = CONNECTION_GROUP.AddJoint() JOINT_GENERAL.ConnectionType = JointScopingType.BodyToGround JOINT_GENERAL.Type = JointType.General JOINT_GENERAL.TranslationZ = FixedOrFree.Free JOINT_GENERAL.MobileLocation = NS_FIXED_FACE # The below commands help in setting the rotational dofs JOINT_GENERAL.Rotations = JointRotationDOFType.FreeAll JOINT_GENERAL.Rotations = JointRotationDOFType.FixAll #Scenario 5 - Define Mesh Settings MESH.ElementSize = Quantity("0.25 [m]") MESH.GenerateMesh() #Scenario 6 - Insert Displacement BC DISPLACEMENT_BC = STATIC_STRUCTURAL.AddDisplacement() DISPLACEMENT_BC.Location = NS_BC_FACE DISPLACEMENT_BC.ZComponent.Output.DiscreteValues = [Quantity("0.01 [m]")] #Scenario 7 - Insert Results DIRECTIONAL_DEFORMATION = STATIC_STRUCTURAL_SOLUTION.AddDirectionalDeformation() DIRECTIONAL_DEFORMATION.NormalOrientation = NormalOrientationType.ZAxis JOINT_PROBE_RELATIVE_DISPLACEMENT = STATIC_STRUCTURAL_SOLUTION.AddJointProbe() JOINT_PROBE_RELATIVE_DISPLACEMENT.BoundaryConditionSelection = JOINT_GENERAL JOINT_PROBE_RELATIVE_DISPLACEMENT.ResultType = ProbeResultType.DeformationProbe JOINT_PROBE_RELATIVE_DISPLACEMENT.ResultSelection = ProbeDisplayFilter.ZAxis #Scenario 8 - Solve and review the results STATIC_STRUCTURAL_SOLUTION.Solve(True) DIRECTIONAL_DEFORMATION_MAX = DIRECTIONAL_DEFORMATION.Maximum.Value DIRECTIONAL_DEFORMATION_MIN = DIRECTIONAL_DEFORMATION.Minimum.Value JOINT_PROBE_RELATIVE_DISPLACEMENT_MAX = JOINT_PROBE_RELATIVE_DISPLACEMENT.MaximumZAxis.Value JOINT_PROBE_RELATIVE_DISPLACEMENT_MIN = JOINT_PROBE_RELATIVE_DISPLACEMENT.MinimumZAxis.Value
Summary
This example demonstrates how scripting in Mechanical can be used to automate your actions.