API Examples: Model Object

This section addresses the programming calls that query for properties of Geometry, Mesh, and Connections properties within the Model object of the ANSYS Mechanical tree.

The following examples all share the same four general steps:

  1. Obtain the tree item under which the object will be created.

  2. Create the object.

  3. Create the selection information on which the object will be based.

  4. Specify property values for the object.

Geometry: Point Mass

This example shows how to use ACT API to customize the Geometry object in the ANSYS Mechanical tree. Specifically, it illustrates how to add a point mass on a face of the geometry and activate the pinball region.

geometry = ExtAPI.DataModel.Project.Model.Children[0] 

point_mass = geometry.AddPointMass() 

my_selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities) 
my_selection.Ids = [22] 
point_mass.Location = my_selection 
point_mass.Mass = Quantity("12 [kg]") 
point_mass.MassMomentOfInertiaX = Quantity("1.1 [kg m m]")
point_mass.MassMomentOfInertiaY = Quantity("1.2 [kg m m]")
point_mass.MassMomentOfInertiaZ = Quantity("1.3 [kg m m]")
point_mass.Behavior = LoadBehavior.Coupled
point_mass.PinballRegion = Quantity("0.2 [m]")

It results in the creation of the point mass and activation of the pinball region in ANSYS Mechanical, as shown below:

Mesh: Mesh Control

This example shows how to use ACT API to customize the Mesh object in the ANSYS Mechanical tree. Specifically, it illustrates how to create a meshing control that applies the Patch Independent algorithm to the mesh.

mesh = ExtAPI.DataModel.Project.Model.Mesh

mesh_method = mesh.AddAutomaticMethod()

my_selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
my_selection.Ids = [16]
mesh_method.Location = my_selection
mesh_method.Method = MethodType.AllTriAllTet
mesh_method.Algorithm = MeshMethodAlgorithm.PatchIndependent
mesh_method.MaximumElementSize = Quantity("0.05 [m]")
mesh_method.FeatureAngle = Quantity("12.000000000000002 [degree]")
mesh_method.MeshBasedDefeaturing = True
mesh_method.DefeaturingTolerance = Quantity("0.0001 [m]")
mesh_method.MinimumSizeLimit = Quantity("0.001 [m]")
mesh_method.NumberOfCellsAcrossGap = 1
mesh_method.CurvatureNormalAngle = Quantity("36 [degree]")
mesh_method.SmoothTransition = True
mesh_method.TetraGrowthRate = 1

It results in the creation of a Patch Independent meshing control in ANSYS Mechanical, as shown below:

Connections: Frictionless Contact and Beam

This example shows how to use the ACT API to customize the Connections object in the ANSYS Mechanical tree. Specifically, it illustrates how to add a frictionless contact and a beam connection.

connection = ExtAPI.DataModel.Project.Model.Connections
contact_region = connection.Children[0].Children[0]
contact_region.ContactType = ContactType.Frictionless

beam = connection.AddBeam()
beam.Radius = Quantity("0.005 [m]")
reference_scoping = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
reference_scoping.Ids = [110]
beam.ReferenceLocation = reference_scoping
beam.ReferenceBehavior = LoadBehavior.Deformable
beam.ReferencePinballRegion = Quantity("0.001 [m]")
mobile_scoping = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
mobile_scoping.Ids = [38]
beam.MobileLocation = mobile_scoping
beam.MobileZCoordinate = Quantity("6.5E-03 [m]")
beam.MobilePinballRegion = Quantity("0.001 [m]")

It results in the creation of a frictionless contact and beam connection in ANSYS Mechanical, as shown below:

Analysis: Load Magnitude

This example shows how to use the ACT API to customize an Analysis object in the ANSYS Mechanical tree, adding the magnitude of a load. Specifically, it illustrates how to customize a Static Structural analysis, specifying the external and internal pressure exerted on a pipe and then applying a force to a section of the pipe.

static_structural = ExtAPI.DataModel.Project.Model.Analyses[0]
analysis_settings = static_structural.AnalysisSettings.NumberOfSteps = 4

bolt = static_structural.AddBoltPretension()
bolt_scoping = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
bolt_scoping.Ids = [200]
bolt.Location = bolt_scoping
bolt.DefineBy = BoltLoadDefineBy.Load
bolt.Preload = Quantity("15 [N]")

support = static_structural.AddFixedSupport()
support_scoping = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
support_scoping.Ids = [104]
support.Location = support_scoping

pressure = static_structural.AddPressure()
pressure_scoping = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
pressure_scoping.Ids = [220]
pressure.Location = pressure_scoping
pressure.Magnitude.Output.Formula = '10*time'

pressure = static_structural.AddPressure()
pressure_scoping = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
pressure_scoping.Ids = [221]
pressure.Location = pressure_scoping
pressure.Magnitude.Output.DiscreteValues=[Quantity('6 [Pa]')]

force = static_structural.AddForce()
force_scoping = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
force_scoping.Ids = [219]
force.Location = force_scoping
force.Magnitude.Output.DiscreteValues=[Quantity('11.3 [N]'), Quantity('12.85 [N]')]

In our example, we apply the internal and external pressures to the pipe:

pressure.Magnitude.Output.Formula = '10*time'
pressure.Magnitude.Output.DiscreteValues=[Quantity('6 [Pa]')]

Then we use tabular data to apply a vector force to the pipe:


Note:  If you use a constant ramped from t=0s to define the force, the first value cannot be "0".


force.Magnitude.Output.DiscreteValues=[Quantity('11.3 [N]'), Quantity('12.85 [N]')]

Script execution results in the creation of a Magnitude property for the applied Force, with time as an input variable and a single output variable:

Although initially we used tabular data to define the Magnitude property, we can also use a constant value or a time- or space-dependent formula. Below is an example of how to use a constant value to define the property:

force.Magnitude.Output.DiscreteValues=[Quantity('10 [N]')] 

We can also opt to define the Magnitude property with global coordinates, instead of a vector, by using the following commands:

force.DefineBy = LoadDefineBy.Components
force.ZComponent.Output.DiscreteValues = [Quantity('0 [N]'),Quantity('-9 [N]')]

Result: Total Deformation Maximum

This example shows how to use the ACT API to customize the Result object in the ANSYS Mechanical tree. Specifically, it illustrates how to add a Total Deformation result to a Static Structural analysis and then solve for the minimum and maximum total deformation.

solution = ExtAPI.DataModel.Project.Model.Analyses[0].Solution
total_deformation = solution.AddTotalDeformation()
analysis = ExtAPI.DataModel.Project.Model.Analyses[0]
analysis.Solve(True)
minimum_deformation = total_deformation.Minimum
maximum_deformation = total_deformation.Maximum

It results in a solved analysis indicating the values for the Minimum and Maximum properties for the Total Deformation result, as shown below:


Release 17.0 - © SAS IP, Inc. All rights reserved.