Project Wizard (Workbench Project Tab)*

The extension ProjectWizard contains a project wizard named WizardDemos that runs from the Workbench Project tab.

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 ProjectWizard reference the script main.py.

Wizard Interface Definition

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

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

  • 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 Layout Definition

The <uidefinition> block defines a set of layouts for the user interfaces of the wizards. For the sake of this example, the contents of this block have been removed from the excerpt of the XML extension definition file that is shown after the code block definitions. For more information, see Customizing the Layout of a Wizard and the example Wizard Custom Layout Example.

Wizard Definition

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

  • 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 the Workbench Project tab, context is set to Project.

  • 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 six steps: Geometry, Mechanical, Fluent, ReportView, CustomStep, and Charts.

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 main.py.

    • For the step Geometry, the callback <onupdate> executes the function EmptyAction. The callback <onreset> executes the function DeleteGeometry. The callback <oninit> executes the function InitTabularData.

    • For the step Mechanical, the callback <onupdate> executes the function EmptyAction. The callback <onreset> executes the function DeleteMechanical.

    • For the step Fluent, the callback <onrefresh> executes the function CreateDialog. The callback <onupdate> executes the function EmptyAction. The callback <onreset> executes the function EmptyReset.

    • For the step ReportView, the callback <onrefresh> executes the function RefreshReport. The callback <onreset> executes the function EmptyReset.

    • For the step CustomStep, the callback <onrefresh> executes the function RefreshMechanical. The callback <onupdate> executes the function LogReport. The callback <onreset> executes the function EmptyReset.

    • For the step Charts, the callback <onrefresh> executes the function RefreshCharts.

  • Any <propertygroup> blocks specify groupings of properties within the step. Any <property> blocks specify properties and property attributes. For properties requiring validation, the callback <onvalidate> executes the appropriate validation function.

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">Caption property
		<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="ProjectWizard" version="1" context="Project" icon="wizard_icon">
		<description>Simple wizard for demonstration in Project page.</description>
		
		<step name="Geometry" caption="Geometry" version="1" HelpFile="help/geometry.html" 
layout="DefaultTabularDataLayout">
			<description>Create a geometry component.</description>
			
			<componentStyle component="Submit">
				<background-color>#b6d7a8</background-color>
			</componentStyle>

			<componentData component="TabularData">
				<CanAddDelete>false</CanAddDelete>
			</componentData>

			<callbacks>
				<onupdate>EmptyAction</onupdate>
				<onreset>DeleteGeometry</onreset>
				<oninit>InitTabularData</oninit>
			</callbacks>
			
			<propertygroup display="caption" name="definition" caption="Basic properties" >
				<property name="filename" caption="Geometry file name" control="fileopen" />
				<property name="myint" caption="Integer value" control="integer" />
				<property name="mytext" caption="Text value" control="text" />
				<property name="myquantity" caption="Quantity value" control="float" unit="Pressure" />
				<property name="myreadonly" caption="Readonly value" control="text" readonly="true" 
default="My value" />
				<propertygroup display="property" name="myselect" caption="List of choice" control="select" 
default="Option1">
					<attributes options="Option1,Option2" />
					<property name="option1" caption="Option1 value" control="text" visibleon="Option1" />
					<property name="option2first" caption="Option2 first value" control="float" unit="Pressure" 
visibleon="Option2" />
					<property name="option2seond" caption="Option2 second value" control="float" unit="Length" 
visibleon="Option2" />
				</propertygroup>
			</propertygroup>

			<propertytable name="Table" caption="Table" control="custom" display="worksheet" 
class="Worksheet.TabularDataEditor.TabularDataEditor">
				<property name="Frequency" caption="Frequency" unit="Frequency" control="float" 
isparameter="true"></property>
				<property name="Damping" caption="Damping" control="float" isparameter="true"></property>
				<property name="TestFileopen" caption="fileopen" control="fileopen"></property>
			</propertytable>

			<propertytable name="TableB" caption="Table B" control="tabulardata" display="worksheet">
				<property name="Integer" caption="Integer" control="integer"></property>
				<property name="FileOpen" caption="Fileopen" control="fileopen"></property>
				<property name="Number" caption="Number A" unit="Pressure" control="float"></property>
				<property name="ReadOnly" caption="ReadOnly" unit="Pressure" control="float" readonly="true" 
default="4 [Pa]"/>
				<propertygroup display="property" name="myselect" caption="List of choice" control="select" 
default="Option1">
					<attributes options="Option1,Option2" />
					<property name="TestStr" caption="Text" control="text" visibleon="Option1"></property>
					<property name="Number B" caption="Number B" unit="Temperature" control="float"></property>
				</propertygroup>
			</propertytable>

		</step>

		<step name="Mechanical" caption="Mechanical" enabled="true" version="1" HelpFile="help/mechanical.html">
			<description>Create a mechanical component.</description>
			
			<callbacks>
				<onupdate>EmptyAction</onupdate>
				<onreset>DeleteMechanical</onreset>
			</callbacks>
			
			<property name="name" caption="System name" control="text" />
			
		</step>	
		
		<step name="Fluent" caption="Fluent" version="1" HelpFile="help/fluent.html">
			<description>Create a fluent component.</description>
			
			<callbacks>
				<onrefresh>CreateDialog</onrefresh>
				<onupdate>EmptyAction</onupdate>
				<onreset>EmptyReset</onreset>
			</callbacks>
			
			
			<property name="name" caption="System name" control="text" />
			<property name="dialog" caption="Dialog" control="text">
				<callbacks>
					<onvalidate>ValidateDialog</onvalidate>
				</callbacks>
			</property>
			<property name="dialog2" caption="DialogProgress" control="text">
				<callbacks>
					<onvalidate>ValidateDialogProgress</onvalidate>
				</callbacks>
			</property>
			<property name="nextstep" caption="Next Step" control="select" >
				<callbacks>
					<onvalidate>ValidateNextStep</onvalidate>
				</callbacks>
			</property>
			
		</step>	
		
		<step name="ReportView" caption="ReportView" version="1" layout="ReportView@WizardDemos">
			<description>Simple example to demonstrate how report can be displayed.</description>
			
			<callbacks>
				<onrefresh>RefreshReport</onrefresh>
				<onreset>EmptyReset</onreset>
			</callbacks>
			
		</step>	
		
		<step name="CustomStep" caption="CustomStep" enabled="true" version="1" layout="MyLayout@WizardDemos">
			<description>Create a mechanical component.</description>
			
			<callbacks>
				<onrefresh>RefreshMechanical</onrefresh>
				<onupdate>LogReport</onupdate>
				<onreset>EmptyReset</onreset>
			</callbacks>
			
			<property name="name" caption="System name" control="text" />
			
		</step>	
		
		<step name="Charts" caption="Charts" enabled="true" version="1" layout="GraphLayout@WizardDemos">
			<description>Demonstrate all chart capabilities.</description>
			
			<callbacks>
				<onrefresh>RefreshCharts</onrefresh>
			</callbacks>
			
		</step>	
		
	</wizard>

	... 
		
</extension>

IronPython Script

The IronPython script main.py follows. It defines all of the functions executed by callbacks in the extension's XML file. Each step defined in the XML file can include multiple actions.

geoSystem = None
dsSystem = None
fluentSystem = None 

def EmptyAction(step):
    pass

def InitTabularData(step):
    table = step.Properties["TableB"]
    for i in range(1, 10):
        table.AddRow()
        table.Properties["Integer"].Value = i
        table.Properties["FileOpen"].Value = "super"
        table.Properties["Number"].Value = 45.21
        table.Properties["ReadOnly"].Value = 777
        table.Properties["myselect"].Properties["TestStr"].Value = 777
        table.Properties["myselect"].Properties["Number B"].Value = 777
        table.SaveActiveRow()

def CreateGeometry(step):
    global geoSystem
    template1 = GetTemplate(TemplateName="Geometry")
    geoSystem = template1.CreateSystem()
    geometry1 = geoSystem.GetContainer(ComponentName="Geometry")
    geometry1.SetFile(FilePath=step.Properties["definition/filename"].Value)

def DeleteGeometry(step):
    global geoSystem
    geoSystem.Delete()
    
def RefreshMechanical(step):
    tree = step.UserInterface.GetComponent("Tree")
    root = tree.CreateTreeNode("Root")
    node1 = tree.CreateTreeNode("Node1")
    node2 = tree.CreateTreeNode("Node2")
    node3 = tree.CreateTreeNode("Node3")
    root.Values.Add(node1)
    root.Values.Add(node2)
    node2.Values.Add(node1)
    node2.Values.Add(node3)
    root.Values.Add(node3)
    tree.SetTreeRoot(root)
    chart = step.UserInterface.GetComponent("Chart")
    chart.Plot([1,2,3,4,5],[10,4,12,13,8],"b","Line1")
    chart.Plot([1,2,3,4,5],[5,12,7,8,11],"r","Line2")

def CreateMechanical(step):
    global dsSystem, geoSystem
    template2 = GetTemplate(
        TemplateName="Static Structural",
        Solver="ANSYS")
    geometryComponent1 = geoSystem.GetComponent(Name="Geometry")
    dsSystem = template2.CreateSystem(
        ComponentsToShare=[geometryComponent1],
        Position="Right",
        RelativeTo=geoSystem)
    if step.Properties["name"].Value=="error":
        raise UserErrorMessageException("Invalid system name. Please try again.")
    dsSystem.DisplayText = step.Properties["name"].Value

def DeleteMechanical(step):
    global dsSystem
    dsSystem.Delete()

def CreateFluent(step):
    global dsSystem, fluentSystem
    template3 = GetTemplate(TemplateName="Fluid Flow")
    geometryComponent2 = dsSystem.GetComponent(Name="Geometry")
    solutionComponent1 = dsSystem.GetComponent(Name="Solution")
    componentTemplate1 = GetComponentTemplate(Name="CFDPostTemplate")
    fluentSystem = template3.CreateSystem(
        ComponentsToShare=[geometryComponent2],
        DataTransferFrom=[Set(FromComponent=solutionComponent1, TransferName=None, 
ToComponentTemplate=componentTemplate1)],
        Position="Right",
        RelativeTo=dsSystem)
    if step.Properties["name"].Value=="error":
        raise Exception("Invalid system name. Please try again.")
    fluentSystem.DisplayText = step.Properties["name"].Value

def CreateDialog(step):
    comp = step.UserInterface.Panel.CreateOKCancelDialog("MyDialog", "MyTitle", 400, 150)
    comp.SetOkButton("Ok")
    comp.SetMessage("My own message")
    comp.SetCallback(cbDialog)
    prop = step.Properties["nextstep"]
    prop.Options.Clear()
    s = step.NextStep
    val = s.Caption
    while s!=None:
        prop.Options.Add(s.Caption)
        s = s.NextStep
    prop.Value = val

def cbDialog(sender, args):
    dialog = CurrentWizard.CurrentStep.UserInterface.GetComponent("MyDialog").Hide()

def ValidateDialog(step, prop):
    dialog = step.UserInterface.GetComponent("MyDialog")
    dialog.Show()

def worker(step):
    progressDialog = step.UserInterface.GetComponent("Progress")
    progress = progressDialog.GetFirstOrDefaultComponent()
    progress.Reset()
    stopped = progress.UpdateProgress("Start progress...", 0, True)
    progressDialog.Show()
    for i in range(100):
        System.Threading.Thread.Sleep(100)
        stopped = progress.UpdateProgress("Start progress...", i+1, True)
        if stopped:
            break
    progressDialog.Hide()
    
def ValidateDialogProgress(step, prop):
    thread = System.Threading.Thread(System.Threading.ParameterizedThreadStart(worker))
    thread.Start(step)
    
def ValidateNextStep(step, prop):
    prop = step.Properties["nextstep"]
    s = step.NextStep
    v = False
    while s!=None:
        if prop.Value==s.Caption:
            v = True
        s.IsEnabled = v
        s = s.NextStep
    steps = step.UserInterface.GetComponent("Steps")
    steps.UpdateData()
    steps.Refresh()

def RefreshReport(step):
    report = step.UserInterface.GetComponent("Report")
    report.SetHtmlContent(System.IO.Path.Combine(ExtAPI.Extension.InstallDir,"help","report.html"))
    report.Refresh()
    
def EmptyReset(step):
    pass
    
def LogReport(step):
    ExtAPI.Log.WriteMessage("Report:")
    for s in step.Wizard.Steps.Values:
        ExtAPI.Log.WriteMessage("Step "+s.Caption)
        for prop in s.AllProperties:
            ExtAPI.Log.WriteMessage(prop.Caption+": "+prop.DisplayString)

import random
import math

def RefreshCharts(step):
    graph = step.UserInterface.GetComponent("Graph")
    graph.Title("Line Bar Graph")
    graph.ShowLegend(False)
    graph.Plot([-1, 0, 1, 2, 3, 4],  [0.5, -0.5, 0.5, -0.5, 0.5, 0.5], key="Variable A", color='g')
    graph.Bar([-1, 0, 1, 2, 3, 4],  [10, 20, 30, 10, 5, 20], key="Variable B")

    graphB = step.UserInterface.GetComponent("GraphB")
    graphB.Title("Plot Graph")
    graphB.YTickFormat("0.2f")

    xValues = []
    yValues = []
    for i in range(0, 100):
        xValues.append(i)
        yValues.append(abs(math.sin(i*0.2))*i/100.0)
    graphB.Plot(xValues, yValues, key="y = a*sin(bx)", color="c")
    graphB.Plot(xValues, yValues, key="y = x", color="m")

    xValues = []
    yValues = []
    for i in range(0, 100):
        xValues.append(i)
        yValues.append(i/100.0)
    graphB.Plot(xValues, yValues, key="y = x", color="m")

    graphB.Plot([0, 10, 20, 30, 100], [0.2, 0.2, 0.2, 0.3, 0.3], key="Smth", color="r")
    graphB.Plot([0, 10, 20, 30, 100], [0.2, 0.1, 0.3, 0.5, 0.7], key="Smth", color="r")
    graphB.Plot([0, 10, 20, 30, 100], [0.2, 0.2, 0.2, 0.3, 0.3])

    graphC = step.UserInterface.GetComponent("GraphC")
    graphC.Title("Pie Graph")
    graphC.Pie([1, 2, 3])
    graphC.Pie([20, 30, 5, 15, 12], [0, "Banana", 2, 3, "42"])

    graphD = step.UserInterface.GetComponent("GraphD")
    graphD.Title("Bar Graph")
    graphD.Bar(["Banana"], [70], key="key")
    graphD.Bar([0, "Banana", 2, 3, 4], [20, 30, 5, 15, 12], key="key")

    graphE = step.UserInterface.GetComponent("GraphE")
    graphE.Title("Bubble Graph")
    graphE.XTickFormat("f")
    graphE.YTickFormat("f")
    keys = ["one", "two", "three", "four", "five"]
    colors = ["#BB3333", "#33BB33", "#3333BB", "#BBBB33", "#BB33BB"]
    for c in range(0, 5):
        xValues = []
        yValues = []
        sizeValues = []
        for i in range(0, (c+1)*20):
            rad = random.randrange(c+1, c+2) + (random.random()*2-1)
            angle = random.random() * 2 * math.pi
            xValues.append(math.cos(angle) * rad)
            yValues.append(math.sin(angle) * rad)
            sizeValues.append(random.random() * 2.0 + 0.5)
        graphE.Bubble(xValues, yValues, sizeValues, key=keys[c], color=colors[c])

def CreateStaticStructural(step):
    template1 = GetTemplate(
        TemplateName="Static Structural",
        Solver="ANSYS")
    system1 = template1.CreateSystem()
    system1.DisplayText = "toto"

    nextStep = step.NextStep
    if nextStep!=None:
        nextStep.SystemName = system1.Name
        nextStep.ComponentName = "Geometry"
    nextStep = nextStep.NextStep
    if nextStep!=None:
        nextStep.SystemName = system1.Name
        nextStep.ComponentName = "Geometry"
    nextStep = nextStep.NextStep
    if nextStep!=None:
        nextStep.SystemName = system1.Name
        nextStep.ComponentName = "Geometry"
    nextStep = nextStep.NextStep
    if nextStep!=None:
        nextStep.SystemName = system1.Name
        nextStep.ComponentName = "Geometry"
    nextStep = nextStep.NextStep
    if nextStep!=None:
        nextStep.SystemName = system1.Name
        nextStep.ComponentName = "Model"
    nextStep = nextStep.NextStep
    if nextStep!=None:
        nextStep.SystemName = system1.Name
        nextStep.ComponentName = "Model"

def OnSelectContext(step, prop):
    firstDMStep = step.NextStep
    secondDMStep = firstDMStep.NextStep
    firstSCStep = secondDMStep.NextStep
    secondSCStep = firstSCStep.NextStep

    firstGeoStep = step.NextStep
    if prop.Value == "DesignModeler":
        firstDMStep.IsEnabled = True
        secondDMStep.IsEnabled = True
        firstSCStep.IsEnabled = False
        secondSCStep.IsEnabled = False
    elif prop.Value == "SpaceClaim":
        firstDMStep.IsEnabled = False
        secondDMStep.IsEnabled = False
        firstSCStep.IsEnabled = True
        secondSCStep.IsEnabled = True

    panel = step.UserInterface.Panel.GetComponent("Steps")
    panel.UpdateData()
    panel.Refresh()


def RefreshResultsProject(step):
    step.Properties["Res"].Value = ExtAPI.Extension.Attributes["result"]
    panel = step.UserInterface.Panel.GetComponent("Properties")
    panel.UpdateData()
    panel.Refresh()

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