This section discusses customization of ANSYS AIM for the native exposure of a preprocessing feature—specifically, how to add a custom load to a structural analysis. The example used in the discussion is defined in the extension CustomPressure, which was written to create a custom pressure as a load. This example is for demonstration purposes only.
The XML extension definition file and IronPython script are addressed separately.
The XML extension definition file CustomPressure.xml follows. This code adds the custom pressure load to the project.
<extension version="1" name="CustomPressure">
<guid shortid="CustomPressure">314bd00a-2f64-4b62-8196-bab9206c2c6b</guid>
<script src="main.py" />
<simdata context="Study">
<load name="CustomPressure" version="1" caption="CustomPressure" icon="tload" issupport="false"
isload="true" color="#0000FF" >
<callbacks>
<getsolvecommands order="1">writeNodeId</getsolvecommands>
</callbacks>
<property name="Geometry" caption="Geometry" control="scoping">
<attributes selection_filter="face" />
</property>
<property name="Expression" caption="Expression" datatype="double" control="float"
unit="Pressure" isparameter="true"></property>
</load>
</simdata>
</extension>As in previous examples, this file first defines the extension using the
attributes version and name. The
<script> block specifies the IronPython script
main.py.
The <simdata> block encapsulates the definition
of the load. The attribute context is set to
Study to indicate that the extension is for AIM. The
attributes in the <load> block provide the name,
version, caption, icon, support status, and color that apply to this load. The
attribute color is defined in a hexadecimal format. This
color is used to contrast the load when it is displayed on the model. The
<callbacks> block encapsulates the function
<getsolvecommands>. This IronPython function is
called when the solver input file is generated by AIM. Consequently, the related
IronPython function is responsible for generating the commands that describe the
load within the ANSYS input file.
In the callback definition, the properties to apply to the actual definition of the load are specified. These properties are displayed in the specific ACT object created by the extension, where the user provides the necessary values to complete the load definition.
Neither of these properties requires you to define a callback.
The first property, Geometry, uses a
scoping control type and has the attribute
selection_filter set to
face. This property allows the user to select
the face of the geometry to which to apply the custom pressure.
The second property, Expression, uses a
float control type, which provides the
property with access to AIM expressions functionality. Consequently, you
can enter an expression into the Expression field
and expect a float. Setting datatype to
double introduces a physical quantity
dependency with the unit option, which is set to
Pressure. This combination specifies that
this property is consistent with a pressure. Finally, setting
isparameter to true
specifies that this expression can be parameterized.
The IronPython script main.py for the extension CustomPressure follows.
def writeNodeId(load, stream):
ExtAPI.Log.WriteMessage("writeNodeId...")
stream.WriteLine("/com, GetSolveCommands")
property_expression = load.PropertyByName("Expression")
expression = property_expression.Value
ExtAPI.Log.WriteMessage(expression.ToString())
if expression=="":
return None
property_geometry = load.PropertyByName("Geometry")
refIds = property_geometry.Value.Ids
ExtAPI.Log.WriteMessage(refIds.ToString())
mesh = ExtAPI.DataModel.MeshDataByName("Mesh 1")
for refId in refIds:
meshRegion = mesh.MeshRegionById(refId)
ExtAPI.Log.WriteMessage(meshRegion.ToString())
nodeIds = meshRegion.NodeIds
for nodeId in nodeIds:
node = mesh.NodeById(nodeId)
stream.WriteLine("F,"+nodeId.ToString()+", FX,"+expression.ToString()+"\n")The script main.py defines the function
writeNodeId, which writes the value of the property
Expression on the geometry nodes scoped for the load.
The following figure shows how the load CustomPressure
that you created in ACT is now available as a boundary condition in AIM.
The following figure shows the status of the load once all of the properties are defined.