The extension StudyDemo contains a product target wizard
for AIM named StudyDemo1. This wizard has only one step. In
AIM, wizards for simulations are called custom templates.
Definitions follow for codes blocks in the XML extension definition file StudyDemo.xml.
The <extension> block is the top-most
level in the hierarchy.
The attributes name and
version specify the extension
name and version.
The attribute icon specifies
the image file to display as the icon for the extension.
You specify the location of the
images folder for all images
used by the extension in the
<interface> block.
The attribute description
specifies the text to display in the extension details
accessed via the right-click About
option in the Extension Manager
when it is accessed from the ACT Start
Page.
The <guid> block specifies a unique
identifier for the extension.
The <script> block specifies the
IronPython script that is referenced by the extension. This
extension references main.py.
The <interface> block defines the
user interface for the wizard.
The attribute context is set to
Study because the extension
runs from ANSYS AIM. In AIM, a
study is the workspace in
which you create and define one or more simulation
processes.
The attribute images specifies
the images folder for all images
that the extension is to use. You use the attribute
icon for the extension,
wizard, step, and so on to specify an image file in this
folder to use as an icon.
The custom template StudyDemo1 is defined
in the <wizard> block named
StudyDemo1. This custom template has only
a single step.
The attributes name and
version specify the wizard
name and version.
The attribute context specifies
the ANSYS product in which the wizard is executed.
Because the wizard runs from AIM,
context is set to
Study.
The attribute icon specifies
the filename for the image to display for the custom
template on the AIM start page and when adding a new
simulation from the Study panel.
The file icon.png is stored in the
folder specified for the attribute
images in the
<interface>
block.
The attribute description
specifies the text to display in the
About window for the extension
when it is accessed from the Extension
Manager and in the
About window for the wizard
when it is accessed from the
Wizards page.
The <step> block defines the
single step of the custom template:
Step1.
The attributes name,
version, and
caption specify the name,
version, and display text for the step.
The attribute context specifies
the ANSYS product in which the specific step is
executed. You only need to set the context for the step
if it differs from the context for the wizard.
The attribute HelpFile
specifies the HTML file to display as the custom help
for the step.
For general information on custom help for wizards and custom templates, see Custom Help for Wizards.
For information on the custom help for this specific example, see Defining Custom Help for the Single-Step Custom Template.
The <property> blocks
specify properties and property attributes for the
step.
The <callbacks> block
defines callbacks to functions defined in the IronPython
script. For a custom template, only the callbacks
<onupdate>,
<onrefresh>, and
<onreset> are
supported.
In this example:
The callback
<onupdate> executes
the function action, which
creates the AIM study.
The callback
<onreset> executes
the function reset, which
allows you to modify the template
properties.
The <properties> block
defines a property used in a step.
For the property
Geometry, the attribute
control is set to
fileopen, which displays a
file selection property initialized to the default
attribute value. The child
<help> block indicates
the text message to display as the custom help for
this property: The geometry file to
import.
For the property
NAnalysis:
The attribute control
is set to integer, which
allows you to edit the integer value for the
default attribute. The child
<help> block indicates
the text message to display as the custom help for
this property: The number of static
structural analyses to create. You must enter an
integer greater than 0.
The callback
<isvalid> invokes the
function isvalid, which
validates that the entered integer is not less
than 1. A custom message can be displayed when the
entered value fails validation.
The XML extension definition file StudyDemo.xml follows.
<extension version="1" name="StudyDemo"> <author>ANSYS Inc.</author> <guid shortid="StudyDemo">150c0680-292b-4291-b46d-bac59949cd56</guid> <script src="main.py" /> <interface context="Study"> <images>images</images> </interface> <wizard name="StudyDemo1" version="1" context="Study" icon="icon"> <description>Wizard to demonstrate the concept inside AIM.</description> <step name="Step1" caption="Load geometry file" version="1" context="Study" helpFile="help/StudyDemo1.html"> <description>Import a geometry file.</description> <callbacks> <onupdate>action</onupdate> <onreset>reset</onreset> </callbacks> <property name="Geometry" caption="Geometry filename" control="fileopen" default="ANSYSInputs"> <help>The geometry file to import.</help> <property name="NAnalysis" caption="Number of analyses" control="integer" default="1"> <help>The number of static structural analyses to create. You must enter an integer greater than 0.</help> <callbacks> <isvalid>isvalid</isvalid> </callbacks> </property> </step> </wizard> </extension>
The IronPython script main.py follows. This script defines all the functions executed by the callbacks in the XML extension definition file for the custom template.
The function action is the single step in the
custom template. When the
button is clicked, the callback <onupdate>
is invoked. It creates the workflow by
creating and updating the ,
, and
tasks.
The callback <onreset> invokes the
function reset, which resets the user interface
and allows the user to modify properties defined for the custom
template. This occurs when encountering an error during the execution of
the callback <onupdate>.
The callback <isvalid> in the
<property> block invokes the function
isvalid, which validates that the property
value entered is not less than 1. A custom message can be displayed when
the entered value fails validation.
tasksToDelete = []
groupsToDelete = []
def action(step):
global tasksToDelete,groupsToDelete
tasksToDelete = []
groupsToDelete = []
system1 = GetSystem(Name="Study")
importComponent1 = Study.CreateTask(
Type="Import",
System=system1)
tasksToDelete.Add(importComponent1)
study1 = system1.GetContainer(ComponentName="Study")
import1 = importComponent1.GetTaskObject()
geometryImportSource1 = study1.CreateEntity(
Type="GeometryImportSource",
Association=import1)
geometryImportSource1.FilePath = step.Properties["Geometry"].Value
geometryImportSource1.GenerateImportSourceOperation()
step.UpdateProgressInformation(10.)
pct = 10.
for i in range(step.Properties["NAnalysis"].Value):
meshingComponent1 = Study.CreateTask(
Type="Meshing",
System=system1,
Input=importComponent1)
tasksToDelete.Add(meshingComponent1)
meshingComponent1.Refresh()
physicsSolutionGroup1 = Study.CreateGroup(Name="Physics Solution")
groupsToDelete.Add(physicsSolutionGroup1)
physicsDefinitionComponent1 = Study.CreateTask(
Type="Physics Definition",
System=system1)
tasksToDelete.Add(physicsDefinitionComponent1)
solvePhysicsComponent1 = Study.CreateTask(
Type="Solve Physics",
System=system1)
tasksToDelete.Add(solvePhysicsComponent1)
physicsSolutionGroup1.Add(Component=physicsDefinitionComponent1)
physicsSolutionGroup1.Add(Component=solvePhysicsComponent1)
AddSourceToComponentInSystem(
SourceComponent=physicsDefinitionComponent1,
TargetComponent=solvePhysicsComponent1)
AddSourceToComponentInSystem(
SourceComponent=meshingComponent1,
TargetComponent=physicsDefinitionComponent1)
physicsDefinitionComponent1.Refresh()
solvePhysicsComponent1.Refresh()
physicsDefinition1 = physicsDefinitionComponent1.GetTaskObject()
physicsRegion1 = study1.CreateEntity(
Type="PhysicsRegion",
Association=physicsDefinition1)
solverSettings1 = study1.CreateEntity(
Type="SolverSettings",
Association=physicsDefinition1)
transcript1 = study1.CreateEntity(
Type="Transcript",
Association=physicsDefinition1)
physicsDefinitionComponent1.Refresh()
solvePhysicsComponent1.Refresh()
meshing1 = meshingComponent1.GetTaskObject()
meshing1.EngineeringIntent = "StructuralOrThermalOrElectricConduction"
physicsRegion1.Location = ["BODY1"]
physicsRegion1.PhysicsType = "Structural"
materialAssignment1 = study1.CreateEntity(
Type="MaterialAssignment",
Association=physicsDefinition1)
materialAssignment1.Location = ["BODY1"]
material1 = study1.CreateEntity(
Type="Material",
Association=physicsDefinition1)
material1.ImportEngineeringData(Name="Structural Steel")
materialAssignment1.Material = material1
pct += 10.
step.UpdateProgressInformation(pct)
if i==9:
raise UserErrorMessageException("My own error message.")
def reset(step):
global tasksToDelete,groupsToDelete
system1 = GetSystem(Name="Study")
for group in groupsToDelete:
Study.DeleteTaskGroup(Group=group)
for task in tasksToDelete:
task.DeleteTask(System=system1)
def isvalid(step, prop):
if prop.Value<1:
prop.StateMessage = "Must be greater than 0."
return False
return True One custom help file is defined for this custom template:
StudyDemo1.html. Because this wizard is for AIM, the
filename for the custom help file and the name of the step
(Step1) in the XML file do not have to be the same.
The single custom help file references the image file
workflow.png.
In the following figure, the extension StudyDemo is in
the default folder extensions for the current
installation. Within this extension, the HTML and PNG files for the custom help
are in a folder named help.

The <step> block in the XML extension definition
file references the help file for the step:
<step name="Step1" caption="Load geometry file" version="1" context="Study" helpFile="help/StudyDemo1.html">
Additionally, for the two properties in this step, the
<properties> blocks define the custom help to
display:
<property name="Geometry" caption="Geometry filename" control="fileopen" default="ANSYSInputs">
<help>The geometry file to import.</help>
</property>
<property name="nAnalysis" caption="Number of analyses" control="fileopen" default="">
<help>The number of static structural analyses to create. You must enter an integer greater than 0.</help>
<callbacks>
<isvalid>isValid</isvalid>
</callbacks>
</property>