The extension WizardDemos contains a target product wizard
for DesignModeler named CreateBridge. This two-step wizard is
for building a bridge.
Note: The extension WizardDemos contains two wizards named
CreateBridge. The first one is for DesignModeler, and
the second one is for SpaceClaim. This topic describes the wizard for
DesignModeler. The next topic describes the wizard for SpaceClaim.
Definitions follow for codes blocks in the XML extension definition file WizardDemos.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 <guid> block specifies a unique
identifier for the extension.
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 CreateBridge for DesignModeler
reference the script dm.py.
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 second <interface> block
has the attribute context set to
DesignModeler, which indicates
that wizards with their context set to this ANSYS product
use the interface defined by this block. The wizard
CreateBridge for DesignModeler
uses this <interface> block. It
has a <toolbar> block that
defines two toolbar buttons for exposure in DesignModeler.
When the buttons are clicked, the callback
<onclick> executes the
functions CreateDeck and
CreateSupport, creating a deck
geometry with supports.
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.
The two <simdata> blocks provide data
for the creation of the geometries Deck and
Support.
The wizard CreateBridge and its steps are
defined in the <wizard> block named
CreateBridge. The first wizard
CreateBridge is for DesignModeler.
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 DesignModeler,
context is set to
DesignModeler.
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.
The <step> blocks define the steps of
the wizard. This wizard has two steps: Deck
and Supports.
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
dm.py.
For the step Deck, the
callback <onupdate>
executes the function
UpdateDeck, creating the
deck using the geometry
Deck.
For the step Supports, the
callback <onupdate>
executes the function
UpdateSupports, creating
the bridge supports using the geometry
Support.
Any <propertygroup> blocks
specify groupings of properties within the step. Any
<property> blocks specify
properties and property attributes.
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>
<simdata context="DesignModeler">
<geometry name="Deck" caption="Deck" icon="deck" version="1">
<callbacks>
<ongenerate>GenerateDeck</ongenerate>
</callbacks>
<property name="Length" caption="Length" control="float" unit="Length" default="300 [m]" />
<property name="Width" caption="Width" control="float" unit="Length" default="20 [m]" />
<property name="Beams" caption="Beams" control="integer" default="31" />
</geometry>
</simdata>
<simdata context="DesignModeler">
<geometry name="Support" caption="Support" icon="support" version="1">
<callbacks>
<ongenerate>GenerateSupport</ongenerate>
</callbacks>
<property name="Length" caption="Length" control="float" unit="Length" default="300 [m]" />
<property name="Height" caption="Height" control="float" unit="Length" default="100 [m]" />
<property name="Width" caption="Width" control="float" unit="Length" default="20 [m]" />
<property name="Number" caption="Number" control="integer" default="3" />
</geometry>
</simdata>
...
<wizard name="CreateBridge" version="1" context="DesignModeler" icon="wizard_icon">
<description>Simple wizard for demonstration in DesignModeler.</description>
<step name="Deck" caption="Deck" version="1" HelpFile="help/dm1.html">
<description>Create the deck.</description>
<callbacks>
<onupdate>UpdateDeck</onupdate>
</callbacks>
<propertygroup display="caption" name="Deck" caption="Deck Definition" >
<property name="Length" caption="Length" control="float" unit="Length" default="300 [m]" />
<property name="Width" caption="Width" control="float" unit="Length" default="20 [m]" />
<property name="Beams" caption="Beams" control="integer" default="31" />
</propertygroup>
</step>
<step name="Supports" caption="Supports" enabled="true" version="1" HelpFile="help/dm2.html">
<description>Create supports.</description>
<callbacks>
<onupdate>UpdateSupports</onupdate>
</callbacks>
<propertygroup display="caption" name="Supports" caption="Supports Definition" >
<property name="Height" caption="Height" control="float" unit="Length" default="100 [m]" />
<property name="Number" caption="Number" control="integer" default="3" />
</propertygroup>
</step>
</wizard>
...
</extension>The IronPython script dm.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.
import units
def CreateDeck(ag):
ExtAPI.CreateFeature("Deck")
def CreateSupport(ag):
ExtAPI.CreateFeature("Support")
def GenerateDeck(feature,fct):
length = feature.Properties["Length"].Value
length = units.ConvertUnit(length, ExtAPI.DataModel.CurrentUnitFromQuantityName("Length"), "m")
width = feature.Properties["Width"].Value
width = units.ConvertUnit(width, ExtAPI.DataModel.CurrentUnitFromQuantityName("Length"), "m")
num = feature.Properties["Beams"].Value
builder = ExtAPI.DataModel.GeometryBuilder
bodies = []
boxGen = builder.Primitives.Solid.CreateBox([0.,-width/2.,-0.3],[length,width/2.,0.])
bodies.Add(boxGen.Generate())
w = (length-0.1*num)/(num-1.)+0.1
for i in range(num-1):
beamGen = builder.Primitives.Solid.CreateBox([i*w,-width/2.,-0.6],[i*w+0.1,width/2.,-0.3])
bodies.Add(beamGen.Generate())
beamGen = builder.Primitives.Solid.CreateBox([length-0.1,-width/2.,-0.6],[length,width/2.,-0.3])
bodies.Add(beamGen.Generate())
beamGen = builder.Primitives.Solid.CreateBox([0.,-width/2.,-1.],[length,-width/2.+0.2,-0.6])
bodies.Add(beamGen.Generate())
beamGen = builder.Primitives.Solid.CreateBox([0.,width/2.-0.2,-1.],[length,width/2.,-0.6])
bodies.Add(beamGen.Generate())
feature.Bodies = bodies
feature.MaterialType = MaterialTypeEnum.Add
return True
def GenerateSupport(feature,fct):
length = feature.Properties["Length"].Value
length = units.ConvertUnit(length, ExtAPI.DataModel.CurrentUnitFromQuantityName("Length"), "m")
height = feature.Properties["Height"].Value
height = units.ConvertUnit(height, ExtAPI.DataModel.CurrentUnitFromQuantityName("Length"), "m")
width = feature.Properties["Width"].Value
width = units.ConvertUnit(width, ExtAPI.DataModel.CurrentUnitFromQuantityName("Length"), "m")
num = feature.Properties["Number"].Value
builder = ExtAPI.DataModel.GeometryBuilder
bodies = []
w = (length-2.*num)/(num+1.)+2.
for i in range(num):
beamGen = builder.Primitives.Solid.CreateBox([(i+1)*w,-width/2.,-1.-height],
[(i+1)*w+2.,width/2.,-1.])
bodies.Add(beamGen.Generate())
beamGen = builder.Primitives.Solid.CreateBox([0.,-width/2.,-5.],[2.,width/2.,-1.])
bodies.Add(beamGen.Generate())
beamGen = builder.Primitives.Solid.CreateBox([length-2.,-width/2.,-5.],[length,width/2.,-1.])
bodies.Add(beamGen.Generate())
feature.Bodies = bodies
feature.MaterialType = MaterialTypeEnum.Freeze
return True
def UpdateDeck(step):
deck = ExtAPI.CreateFeature("Deck")
deck.Properties["Length"].Value = step.Properties["Deck/Length"].Value
deck.Properties["Width"].Value = step.Properties["Deck/Width"].Value
deck.Properties["Beams"].Value = step.Properties["Deck/Beams"].Value
ExtAPI.DataModel.FeatureManager.Generate()
def UpdateSupports(step):
supports = ExtAPI.CreateFeature("Support")
supports.Properties["Length"].Value = step.PreviousStep.Properties["Deck/Length"].Value
supports.Properties["Width"].Value = step.PreviousStep.Properties["Deck/Width"].Value+6
supports.Properties["Height"].Value = step.Properties["Supports/Height"].Value
supports.Properties["Number"].Value = step.Properties["Supports/Number"].Value
ExtAPI.DataModel.FeatureManager.Generate()