In this example, using the support files, you will insert a Rigid Dynamics analysis object into an undefined Mechanical session and execute a sequence of python journal commands that will define and solve the analysis.
This example begins in the Mechanical application. It requires you to download the following Ansys DesignModeler and python files.
Mechanical_RBD_Geometry.agdb
Mechanical_RBD_Script.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_RBD_Geometry.agdb.
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_RBD_Script.py.
Select the Run Script option (
) from the Editor toolbar.
Scripts Illustrated
In this example, the python file automatically performs the following actions:
# Scenario 1 - Set up the Tree Object Items connections = Model.Connections mesh = Model.Mesh transient_rbd = Model.Analyses[0] analysis_settings = transient_rbd.Children[0] solution = transient_rbd.Solution # Scenario 2 - Define Named Selections ns_sphere_surface = DataModel.GetObjectsByName("NS_sphere_surface")[0] ns_concave_surface = DataModel.GetObjectsByName("NS_concave_surface")[0] ns_fixed_surface = DataModel.GetObjectsByName("NS_fixed_surface")[0] # Scenario 3 - Define Fixed Joint fixed_joint = connections.AddJoint() fixed_joint.ConnectionType = JointScopingType.BodyToGround fixed_joint.Type = JointType.Fixed fixed_joint.MobileLocation = ns_fixed_surface # Scenario 4 - Define Contact contact = connections.AddContactRegion() contact.SourceLocation = ns_sphere_surface contact.TargetLocation = ns_concave_surface contact.RestitutionFactor = 0 # Scenario 5 - Define Mesh Settings mesh.Resolution = 4 mesh.ElementSize = Quantity("0.005 [m]") mesh.GenerateMesh() # Scenario 6 - Define Analysis Settings analysis_settings.NumberOfSteps = 1 analysis_settings.SetStepEndTime(1, Quantity("0.5 [s]")) analysis_settings.SetAutomaticTimeStepping(1, AutomaticTimeStepping.On) analysis_settings.SetInitialTimeStep(1, Quantity("0.0001 [s]")) analysis_settings.SetMinimumTimeStep(1, Quantity("0.0000001 [s]")) analysis_settings.SetMaximumTimeStep(1, Quantity("0.05 [s]")) # Scenario 7 - Insert Standard Earth Gravity gravity = transient_rbd.AddEarthGravity() gravity.Direction = GravityOrientationType.NegativeYAxis # Scenario 8 - Insert Results total_deformation = solution.AddTotalDeformation() joint_probe_total_moment = solution.AddJointProbe() joint_probe_total_moment.BoundaryConditionSelection = fixed_joint joint_probe_total_moment.ResultType = ProbeResultType.MomentReaction joint_probe_total_moment.ResultSelection = ProbeDisplayFilter.XAxis # Scenario 9 - Set up Unit System ExtAPI.Application.ActiveUnitSystem = MechanicalUnitSystem.StandardMKS ExtAPI.Application.ActiveAngleUnit = AngleUnitType.Radian ExtAPI.Application.ActiveAngularVelocityUnit=AngularVelocityUnitType.RadianPerSecond # Scenario 10 - Solve and Define the Results solution.Solve(True) maximum_total_deformation = total_deformation.Maximum.Value minimum_total_deformation = total_deformation.Minimum.Value maximum_of_maximum_total_deformation = total_deformation.MaximumOfMaximumOverTime.Value minimum_of_minimum_total_deformation = total_deformation.MaximumOfMaximumOverTime.Value maximum_x_total_moment = joint_probe_total_moment.MaximumXAxis.Value minimum_x_total_moment = joint_probe_total_moment.MinimumXAxis.Value
Summary
This example demonstrates how scripting in Mechanical can be used to automate your actions.