The extension WizardDemos contains a target product wizard
for SpaceClaim named CreateBridge. This two-step wizard is
for building a bridge
Note: The WizardDemos extension contains two wizards named
CreateBridge. The first one is for DesignModeler, and
the second one is for SpaceClaim. This topic describes the wizard for
SpaceClaim. The previous topic describes the wizard for DesignModeler.
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 SpaceClaim reference
the script sc.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 wizard CreateBridge for
SpaceClaim uses this
<interface> block.
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.
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 second wizard
CreateBridge is for SpaceClaim.
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 SpaceClaim, context
is set to SpaceClaim.
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: DeckSC
and SupportsSC.
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
sc.py.
For the step DeckSC, the
callback <onupdate>
executes the function
UpdateDeckSC, creating the
deck using the geometry
Deck.
For the step SupportsSC,
the callback <onupdate>
executes the function
UpdateSupportsSC, 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.
Note: Beginning in release 18.2, the graphics window in SpaceClaim is not updated until the callbacks for a step have been executed. This change ensures graphics stability and better performance.
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="SpaceClaim" icon="wizard_icon">
<description>Simple wizard for demonstration in SpaceClaim.</description>
<step name="DeckSC" caption="DeckSC" version="1" context="SpaceClaim">
<description>Create the deck.</description>
<callbacks>
<onupdate>UpdateDeckSC</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="SupportsSC" caption="SupportsSC" context="SpaceClaim" enabled="true" version="1">
<description>Create supports.</description>
<callbacks>
<onupdate>UpdateSupportsSC</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 sc.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 createBox(xa, ya, za, xb, yb, zb):
win = Window.ActiveWindow
context = win.ActiveContext
part = context.ActivePart
lengthX = xb - xa
lengthY = yb - ya
lengthZ = zb - za
xa = xa + lengthX * 0.5
ya = ya + lengthY * 0.5
p = Geometry.PointUV.Create(0, 0)
body = Modeler.Body.ExtrudeProfile(Geometry.RectangleProfile(Geometry.Plane.PlaneXY, lengthX,
lengthY, p, 0), lengthZ)
designBody = DesignBody.Create(part, "body", body)
translation = Geometry.Matrix.CreateTranslation(Geometry.Vector.Create(xa, ya, za))
designBody.Transform(translation)
def UpdateDeckSC(step):
length = step.Properties["Deck/Length"].Value
width = step.Properties["Deck/Width"].Value
num = step.Properties["Deck/Beams"].Value
createBox(0., -width/2., -0.3, length,width/2., 0.)
w = (length-0.1*num)/(num-1.)+0.1
for i in range(num-1):
createBox(i*w,-width/2.,-0.6, i*w+0.1,width/2.,-0.3)
createBox(length-0.1, -width/2., -0.6, length, width/2., -0.3)
createBox(0., -width/2., -1., length, -width/2.+0.2, -0.6)
createBox(0., width/2.-0.2, -1., length,width/2., -0.6)
return True
def UpdateSupportsSC(step):
length = step.PreviousStep.Properties["Deck/Length"].Value
width = step.PreviousStep.Properties["Deck/Width"].Value
height = step.Properties["Supports/Height"].Value
num = step.Properties["Supports/Number"].Value
w = (length-2.*num)/(num+1.)+2.
for i in range(num):
createBox((i+1)*w, -width/2., -1.-height, (i+1)*w+2., width/2.,-1.)
beamGen = createBox(0., -width/2., -5., 2., width/2., -1.)
beamGen = createBox(length-2., -width/2.,-5., length,width/2., -1.)
return True