C.10.2. Tutorial: Creating a Custom Task

This tutorial describes the steps needed to develop a custom task for inserting a 100 psi pressure load. The tutorial for Creating a Custom Wizard uses the task created below.

View the completed TaskML file for this tutorial.

Steps

Copy the file MechanicalWizard\Tasks\InsertStructuralLoad.xml to a file named Insert100psi.xml in a different folder. Generally, the easiest way to create a custom task is to modify a similar existing task instead of starting from scratch.

task element as follows:

<task id="Insert100psi" disable-if-missing="geometry" check-ambiguity="environment">

The other attributes on the task element disable the task if the Outline contains no geometry and prompts the user to select a particular Environment if the current selection is ambiguous.

Create an object-groups section at the top of the file:

<simulation-wizard version="1.0">
    <object-groups>
        <object-group name="pressure">
            <object-type class="id_Load" type="id_SurfacePressure" />
        </object-group>
    </object-groups>
    ...
</simulation-wizard> 

This creates a custom object-group named "pressure" that contains a single object-group corresponding to the Pressure object type in the Outline. This object group is available in addition to the Standard Object Groups Reference to wizards merging this task.

Modify the strings section as follows:

<strings>
    <language xml:lang="en-us">
        <string id="Insert100psi_Caption">
            Insert Pressure
        </string>
        <string id="Insert100psi_Message">
            Use the Structural button to insert a Pressure load.
            Enter 100 psi for Magnitude.
        </string>
    </language>
</strings> 

The value for the first string id uses the built-in naming convention of the task id and "_Caption" to simplify the task element by omitting the caption attribute. The value for the second string id is arbitrary and referenced by the display-details-callout action defined below. The strings apply to the default language code "en-us." To support other languages, define new strings inside each language section.

Modify the update-event as shown:

<update-event>
    <if><object type="pressure" condition="does-not-exist"/>
        <then>
            <set-status status="incomplete"/>
            <stop/>
        </then>
    </if>
    <if><object type="pressure" condition="exists" state="under-defined"/>
        <then>
            <set-status status="undefined"/>
            <stop/>
        </then>
    </if>
    <set-status status="complete"/>
</update-event> 

Modify the activate-event as shown:

<activate-event>
    <if><object type="pressure" condition="exists" state="under-defined"/>
        <then>
            <select-first-object type="pressure" state="under-defined"/>
            <select-first-undefined-field/>
            <display-details-callout message="Insert100psi_Message" />
            <stop/>
        </then>
    </if>
    <if><level type="environment" condition="is-not-selected"/>
        <then>
            <select-first-object type="environment"/>
        </then>
    </if>
    <click-button toolbar="DS_graphics" button="Surface"/>
    <display-toolbar-callout toolbar="Context" button="Structural" 
        message="Insert100psi_Message" />***
</activate-event>

Note:  ***Note that it was necessary to "word wrap" the long line of code in the above example.


The first if statement checks for an under-defined pressure. The second if statement ensures that the Outline selection is at the Environment level so that the user can insert a Pressure. The click-button action ensures that the surface selection mode is active.

Save the file.

Proceed to the tutorial Creating a Custom Wizard to use this custom task.