Task Logic Implementation
Overview about the two main files required to create a task: the Task file (.tsk) and the Task Implementation file (.tcl).
Task File Elements and Attributes
The Task file uses the .xml file format with the extension .tsk. To learn more about the XML format, see http://www.w3schools.com/xml.
<Process type="TCL_PROC" name="MathTask" impl="MathTask.tcl" iconFile="MathTask.png">
<Param name="operation" type="string" value="ADD" />
<Input name="input_1" datatype="int" value="8" />
<Input name="input_2" datatype="int" value="13"/>
<Output name="output" datatype="int" />
</Process>
TSK File Element | Attribute | Valid Type | Function of the XML Attribute Type |
---|---|---|---|
Process | type= “TCL_PROC” | TCL_PROC | Specifies the language in which the task is authored. In this example the programming language is ITCL. |
name= “MathTask” | user-defined | Specifies the name of the task, which must be unique. This
attribute is unique to the HyperWorks context. In this example the name of the Task file is
MathTask. The names of all HW tasks are located in [ALTAIR_INSTALL]\hw\bin\win64\Packaging.xml. |
|
impl= “MathTask.tcl” | user-defined | Points to the file that contains the implementation
information for the task. In this example the execution logic
is contained in the file:
MathTask.tcl.
Note: This file must
be placed in the same location as the
*.tsk file.
|
|
Param | name= “operation” | user-defined | Defines the variable name used in the Implementation Task
file. The mapping between "name"and the
implementation file is shown here. In this example the variable name defined is operation. |
datatype= “string” | string int |
Specifies the data type of the variable. Valid types are
string, integer and double. In this example, the variable name is of type string. |
|
value= “ADD” | user-defined | Assigns a default value to the variable. In this example the variable name is assigned a default value of “ADD”. |
|
Input | name= “input_1” | user-defined | Defines the “variable name” that is used in the Implementation Task
file. The mapping between “name” and the
implementation file is shown here. In this example the “variable name” is defined as input_1. |
datatype = “int” | string int double |
Specifies the type of variable. Valid types are: string,
integer and double. In this example, the variable name is of type int. |
|
value= “8” | user-defined | Assigns a default value to the variable. In this example the variable name is assigned a default value of 8. |
|
Output | name= “output” | user-defined | Defines the variable name in the Implementation Task
file. The mapping between “name” and the
implementation file is shown here. In this example the variable name is defined as “output”. |
datatype = “int” | string int double |
Defines the type of variable. The valid types are string,
integer and double. In this example the variable name is of
type int.
Note: While default values can be specified as
parameter input, the output is generated with the task
that is executed.
|
<Process type="TCL_PROC" name="MathTask" impl="MathTask.tcl" iconFile="MathTask.png">
<Param name="operation" type="string" value="ADD" />
<Input name="inputObject_1" datatype="intDataClass" datavalue="" />
<Input name="inputObject_2" datatype="intDataClass" datavalue="" />
<Output name="outputObject" datatype="intDataClass" />
</Process>
TCL File Element | Attribute | Output | Parameters |
---|---|---|---|
Input | name= “InputObject_1” | user-defined | Defines the variable name used in the Task Implementation
file. The mapping between “name” and the implementation file is
shown here. In this example the variable name is defined as InputObject_1. |
datatype= “intDataClass” | user-defined | Defines the data type of the variable. Here the data type is
intDataclass. Note: Prior to loading a task, the ITCL class
must be registered with HyperWorks Automate or sourced in the Tcl interpreter.
|
|
datavalue= “ ” | "" | This field is for internal use and must remain null. | |
Output | name= “outputObject” | user-defined | Defines the variable name used in the implementation file.
The mapping between “name” and the implementation file is shown
here. In this example the variable name is defined as outputObject. |
datatype= “intDataClass” | user-defined | Defines the data type of the variable. Here the data type is
the class, intDataclass. Note: Prior to loading a task, the ITCL
class must be registered with HyperWorks Automate or sourced in the
TCL interpreter.
|
Authoring the Implementation Logic for a Task File
- Implementing a Task with ITCL
- The ITCL class that implements a task must inherit the abstract base class ::pc::AbstractTask. The reference below shows how a sample MathTask Implementation file inherits from ::pc::AbstractTask and maps to a Task file.
- Implementing Task User Interface Functions with a MathTask
-
package requires Itcl; namespace import ::Itcl::*; namespace eval ::pc { class MathTask { #AbstractTask to be implemented by Tasks inherit ::pc::AbstractTask #Below is the list of operations public variable OperationTypes "ADD SUBTRACT DIVIDE MULTIPLY" #Below is a parameter type that was defined in the task file public variable operation; #<Param name="operation" type="string" value="ADD" /> #Below is an Input type that was defined in the task file public variable input_1; #<Input name="input_1" type="int" datavalue="8" /> public variable input_2; #<Input name="input_2" type="int" datavalue="13"/> public variable output ; #<Output name="output" type="int" /> public variable tempvariable_1; public variable tempvariable_2; public variable tempoperation; #User Interference Methods public method PreEdit {} {}; public method PostEdit {} {}; #Execution Logic method preExecute {} {}; method execute {} {}; method postExecute {} {}; method constructor {} {}; } }
- Implementing Task Execution Functions with a MathTask
-
See the following example:
Table 5. Code Snippet Description ::itcl::body ::pc::MathTask::postExecute {} { }
This function is called before the core execute function. ::itcl::body ::pc::MathTask::execute {} { switch -exact $operation { "ADD" { set num_out [expr {$input_1 + $input_2}] } "SUBTRACT" { set num_out [expr {$input_1 + $input_2}] } "MULTIPLY" { set num_out [expr {$input_1 + $input_2}] } "DIVIDE" { set num_out [expr {$input_1 + $input_2}] } } }
- This function implements the execution logic for the task.
- A simple math operation has been implemented.
::itcl::body ::pc::MathTask::postExecute {} { }
- This function is called after the core execute function.
- Use this function to clean objects and clear memory.
- Updating the User Interface
- In Automate the User Interface for a task is created only once. The framework then efficiently displays and clears the UI, instead of clearing and recreating it.
- Creating Tool Tips
- To create tool tips for a task, implement the ToolTip function:
Table 7. Code Snippet Description method ToolTip {} { set toolTipValue "ToolTip" return $toolTipValue }
This function lets you create custom, dynamic tool tips. The return value of the function is displayed in the tool tip.