This section addresses the programming calls that query for properties of
Geometry, Mesh, and
Connections properties within the
Model object of the Mechanical tree.
The following examples all share the same four general steps:
Obtain the tree item under which the object is to be created.
Create the object.
Create the selection information on which the object is to be based.
Specify property values for the object.
This example shows how to use the ACT API to customize the Geometry object in the 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 Mechanical.

This example shows how to use the ACT API to export the Geometry object in the Mechanical tree to an STL file. An STL (STereoLithography) file is the most commonly used file format in 3D printing. The following commands get the project model object and geometry object and then export the geometry object to an STL file.
mymodel = ExtAPI.DataModel.Project.Model
geo = mymodel.Geometry
geo.ExportToSTL("C:\Temp\geoasstl.stl")The result is the creation of a geometry file (geoasst1.stl) to the fully qualified directory path (C:\Temp).
This example shows how to use the ACT API to customize the Mesh object in the 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 = 1It results in the creation of a Patch Independent meshing control in Mechanical.
This example shows how to use the ACT API to customize the Connections object in the 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.
This example shows how to use the ACT API to customize an Analysis object in the 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.SetDefineBy(1, BoltLoadDefineBy.Load) # Change definition for step #1.
bolt.Preload.Output.SetDiscreteValue(0, Quantity("15 [N]")) # Change preload value for step #1.
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 this example, you apply the internal and external pressures to the pipe:
pressure.Magnitude.Output.Formula = '10*time'
pressure.Magnitude.Output.DiscreteValues=[Quantity('6 [Pa]')]Then you 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 the property Magnitude for the applied force, with time as an input variable and a single output variable.

Although initially you used tabular data to define the property Magnitude, you can also use a constant value or a time- or space-dependent formula. An example follows of how to use a constant value to define the property.
force.Magnitude.Output.DiscreteValues=[Quantity('10 [N]')] 
You can also opt to define the property Magnitude 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]')]

You can use the ACT API to extract minimum and maximum tabular data for boundary conditions (force, pressure, moment, and so on) from an Analysis object in the Mechanical tree. This example shows how to extract minimum and maximum force quantities from tabular data for an Analysis object. For your reference, the following image displays tabular data for a force and highlights its min and max quantities.
First, to get the project model object, analysis object, force object, and tabular data object, enter:
mymodel = ExtAPI.DataModel.Project.Model anal = mymodel.Analyses[0] f2 = anal.Children[2] f2td = f2.Magnitude.Output
Next, to get the tuple containing the minimum and maximum force quantities and then display these quantities, enter:
mnmxf2 = f2td.MinMaxDiscreteValues mnmxf2
Given the above tabular data, the following results display:
(0 [lbf], 300 [lbf])
The variable mnxf2 is a tuple (pair) of quantities. Each
element in the tuple can be gotten by using the tuple's
Item1 and Item2
properties.
If you want to get and display only the minimum force quantity, you enter:
mnv = mnmxf2.Item1 mnv
Given the above tabular data, the following results display:
(0 [lbf])
If you want to get and display only the maximum force quantity, you enter:
mxv = mnmxf2.Item2 mxv
Given the above tabular data, the following results display:
(300 [lbf])
This example shows how to use the ACT API to customize the Result object in the 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:
