Mechanical Wizard*

The extension WizardDemos contains a target product wizard for Mechanical named SimpleAnalysis. This wizard performs a simple analysis on the bridge built by either the DesignModeler or SpaceClaim wizard CreateBridge.

XML Extension Definition File

Definitions follow for codes blocks in the XML extension definition file WizardDemos.xml.

Extension Definition

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.

Guid Definition

The <guid> block specifies a unique identifier for the extension.

Script Definition

The <script> blocks specify the IronPython scripts that are referenced by the extension. This extension references four scripts: main.py, ds.py, dm.py, and sc.py. The callbacks for steps in the wizard SimpleAnalysis reference the script ds.py.

Wizard Interface Definition

The <interface> blocks define user interfaces for various wizards in the extension. The extension WizardDemos has two interface blocks.

  • The first <interface> block has the attribute context set to Project|Mechanical|SpaceClaim, which indicates that wizards with their contexts set to any of these ANSYS products use the interface defined by this block. The wizard SimpleAnalysis uses this first <interface> block because its attribute context is set to Mechanical.

  • The second <interface> block has the attribute context set to DesignModeler, which indicates that wizards with their contexts set to this ANSYS product use the interface defined by this block.

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 display as the icon.

Wizard Definition

The wizard SimpleAnalysis and its steps are defined in the <wizard> block named SimpleAnalysis.

  • 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 this wizard runs from Mechanical, context is set to Mechanical.

  • The attribute icon specifies the filename of the image to display as the icon for the wizard: wizard_icon. The file wizard_icon.png is stored in the images 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.

Step Definition

The <step> blocks define the steps of the wizard. There are three steps: Mesh, Solution, and Results.

For each step:

  • 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.

  • The <callbacks> block specifies callbacks to functions defined in the script ds.py.

    • For the step Mesh, the callback <onreset> executes the function RemoveControls to clear existing mesh controls. The callback <onupdate> executes the function CreateMeshControls to create new mesh controls.

    • For the step Solution:

      • The callback <onrefresh> executes the function RefreshLoads to initialize various properties, including the number of nodes, number of elements computed in the previous step, and so on.

      • The callback <onreset> executes the function RemoveLoads to clear loads.

      • The callback <onupdate> executes the function CreateLoads to create new loads, create new results, and perform the solve.

    • For the step Results, the callback <onrefresh> executes the function RefreshResults to fill the property value associated with the result of the computation (Maximum of Total Deformation).

  • Any <propertygroup> blocks specify groupings of properties within the step. Any <property> blocks specify properties and property attributes. For properties requiring location selection, the callback <isvalid> executes the function IsLocationValid to validate the selection. A custom message can be shown when the entered value fails validation.

An excerpt from the file WizardDemos.xml follows.

<extension version="2" minorversion="1" name="WizardDemos">
	<guid shortid="WizardDemos">7fdb141e-3383-433a-a5af-32cb19971771</guid>
	<author>ANSYS Inc.</author>
	<description>Simple extension to test wizards in different contexts.</description>

	<script src="main.py" />
	<script src="ds.py" />
	<script src="dm.py" />
	<script src="sc.py" />
	
	<interface context="Project|Mechanical|SpaceClaim">
		<images>images</images>		
	</interface>
	
	<interface context="DesignModeler">
		<images>images</images>		
		
		<toolbar name="Deck" caption="Deck">
			<entry name="Deck" icon="deck">
				<callbacks>
					<onclick>CreateDeck</onclick>
				</callbacks>
			</entry>
			<entry name="Support" icon="Support">
				<callbacks>
					<onclick>CreateSupport</onclick>
				</callbacks>
			</entry>
		</toolbar>
	
	</interface>
	
	...
	
	<wizard name="SimpleAnalysis" version="1" context="Mechanical" icon="wizard_icon">
		<description>Simple wizard to illustrate how to setup, solve and analyse results of a simulation 
process.</description>
		
		<step name="Mesh" caption="Mesh" version="1" HelpFile="help/ds1.html">
			<description>Setup some mesh controls.</description>
			
			<callbacks>
				<onreset>RemoveControls</onreset>
				<onupdate>CreateMeshControls</onupdate>
			</callbacks>
			
			<propertygroup display="caption" name="Sizing" caption="Mesh Sizing" >
				<property name="Location" caption="Edge Location" control="geometry_selection">
					<attributes selection_filter="edge" />
					<callbacks>
						<isvalid>IsLocationValid</isvalid>
					</callbacks>
				</property>
				<property name="Ndiv" caption="Divisions" control="integer" />
			</propertygroup>
			
		</step>
		
		<step name="Solution" caption="Solution" version="1" HelpFile="help/ds2.html">
			<description>Setup loads.</description>
			
			<callbacks>
				<onrefresh>RefreshLoads</onrefresh>
				<onreset>RemoveLoads</onreset>
				<onupdate>CreateLoads</onupdate>
			</callbacks>
			
			<propertygroup display="caption" name="Mesh" caption="Mesh Statistics" >
				<property name="Nodes" caption="Nodes" control="text" readonly="true" />
				<property name="Elements" caption="Elements" control="text" readonly="true" />
			</propertygroup>
			<propertygroup display="caption" name="FixedSupport" caption="Fixed Support" >
				<property name="Location" caption="Face Location" control="geometry_selection">
					<attributes selection_filter="face" />
					<callbacks>
						<isvalid>IsLocationFSValid</isvalid>
					</callbacks>
				</property>
			</propertygroup>
			
		</step>
		
		<step name="Results" caption="Results" version="1" HelpFile="help/ds3.html">
			<description>View Results.</description>
			
			<callbacks>
				<onrefresh>RefreshResults</onrefresh>
			</callbacks>
			
			<property name="Res" caption="Deformation" control="text" readonly="true" />
			
		</step>
		
	</wizard>
		
	... 
		
</extension>

IronPython Script

The IronPython script ds.py follows. This script defines all functions executed by the callbacks in the XML extension definition file. Each step defined in the XML file can include multiple actions.

ef IsLocationValid(step, prop):
    if prop.Value==None:
        return False
    if prop.Value.Ids.Count!=1:
        prop.StateMessage = "Select only one edge."
        return False
    return True

def CreateMeshControls(step):
    model = ExtAPI.DataModel.Project.Model
    mesh = model.Mesh
    sizing = mesh.AddSizing()
    sel = step.Properties["Sizing/Location"].Value
    entity = ExtAPI.DataModel.GeoData.GeoEntityById(sel.Ids[0])
    len = entity.Length
    ids = []
    for part in ExtAPI.DataModel.GeoData.Assemblies[0].Parts:
        for body in part.Bodies:
            for edge in  body.Edges:
                if abs(edge.Length-len)/len<1.e-6:
                    ids.Add(edge.Id)
    sel = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
    sel.Ids = ids
    sizing.Location = sel
    sizing.Type = SizingType.NumberOfDivisions
    sizing.NumberOfDivisions = step.Properties["Sizing/Ndiv"].Value
    step.Attributes.SetValue("sizing", sizing)
    mesh.GenerateMesh()

def RemoveControls(step):
    sizing = step.Attributes["sizing"]
    sizing.Delete()

def IsLocationFSValid(step, prop):
    if prop.Value==None:
        return False
    if prop.Value.Ids.Count!=1:
        prop.StateMessage = "Select only one face."
        return False
    return True

def RefreshLoads(step):
    model = ExtAPI.DataModel.Project.Model
    step.Properties["Mesh/Nodes"].Value = model.Mesh.Nodes.ToString()
    step.Properties["Mesh/Elements"].Value = model.Mesh.Elements.ToString()
    panel = step.UserInterface.GetComponent("Properties")
    panel.UpdateData()
    panel.Refresh()
    
def CreateLoads(step):
    model = ExtAPI.DataModel.Project.Model
    analysis = model.Analyses[0]
    support = analysis.AddFixedSupport()
    sel = step.Properties["FixedSupport/Location"].Value
    entity = ExtAPI.DataModel.GeoData.GeoEntityById(sel.Ids[0])
    area = entity.Area
    ids = []
    for part in ExtAPI.DataModel.GeoData.Assemblies[0].Parts:
        for body in part.Bodies:
            for face in  body.Faces:
                if abs(face.Area-area)/area<1.e-6:
                    ids.Add(face.Id)
    sel = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
    sel.Ids = ids
    support.Location = sel
    loads = []
    loads.Add(support)
    step.Attributes.SetValue("loads", loads)
    
    loads.Add(analysis.AddEarthGravity())
    res = analysis.Solution.AddTotalDeformation()
    step.Attributes.SetValue("res", res)
    loads.Add(res)
    analysis.Solve(True)
    ExtAPI.Extension.SetAttributeValueWithSync("result", res.Maximum.ToString())

def RemoveLoads(step):
    loads = step.Attributes["loads"]
    for load in loads:
        load.Delete()
    
def RefreshResults(step):
    model = ExtAPI.DataModel.Project.Model
    res = step.PreviousStep.Attributes["res"]
    step.Properties["Res"].Value = res.Maximum.ToString()
    panel = step.UserInterface.GetComponent("Properties")
    panel.UpdateData()
    panel.Refresh()

Release 18.2 - © ANSYS, Inc. All rights reserved.