Features Creation

You can describe the purpose or the usage of OTScript classes, attributes, and methods, which correspond to OTScript features.

The first thing to do when creating a feature is to expose the OTScript feature to the report template editor using the -doc option.

This page discusses:

Category and Label

The OTScript feature can be associated with a category. You can specify a label for a feature.

Note: If no category is defined, Extensions is used as the default category.

You can also declare the category in the label.

METHOD ... CATEGORY "Customer" LABEL "Quantity"; // the category is Customer and label is Quantity
METHOD ... LABEL "Quantity"; // the category is Extensions and label is Quantity
METHOD ... LABEL "Customer,Quantity"; // the category is Customer and label is Quantity

Class Pattern

The following pattern enables you to define a class:

Syntax
CLASS <class_name> -doc : <type>;

Attribute Pattern

The following pattern enables you to define an attribute:

Syntax

ATTRIBUTE <class_name>.<attribute_name> -doc : <type> CATEGORY <category> LABEL <label>;

Method Pattern

You can provide a help text for methods:METHOD ... LABEL "Format Time" HELPTEXT "See documentation of TIMETOSTR";.

The following pattern enables you to define a method:

Syntax

METHOD <type_name>.<method_name>() -doc : {
...
<code>
...
} LABEL "<category>,<label>"
HELPTEXT "<tooltip>";

Description

Parameter Description
type_name

The internal receiver type name. This name is visible in the tooltip when you hover over the type in the Data tab.

method_name

The internal name of the method. This name is visible in the tooltip when you hover over the method in the Data tab.

code

The code of the method. The last line corresponds to the returned element.

category

The category name displayed in the Data tab.

label

The method name displayed in the Data tab.

tooltip

The tooltip displayed when you hover over in the Data tab.

-doc

The OTScript method can be exposed to Report Template Design using the -doc option, that is made visible. To use this option, the label is mandatory.

Example1

PACKAGE Customer;

CLASS BOMElement -doc : Entity_;
ATTRIBUTE BOMElement.quantity -doc : Integer CATEGORY "Customer" LABEL "Quantity";
ATTRIBUTE BOMElement.reference -doc : PLM.VPMReference CATEGORY "Customer" LABEL "Product reference";

METHOD BOMElement.initialize(ref : PLM.VPMReference) : {
  quantity := 0;
  reference := ref;
  THIS
};

METHOD BOMElement.add() : { quantity := quantity + 1 };

CLASS BOM -doc : Entity_;
ATTRIBUTE BOM.elements -doc : BOMElement CATEGORY "Customer" LABEL "BOM Elements";

METHOD BOM.addProductReference(ref : PLM.VPMReference) -doc : {
  TMP element := dictionary.at(ref.id)[EACH ISA BOMElement];
  $NO(element) IF TRUE: {
    element := NEW(BOMElement).initialize(ref);
    dictionary.atPut(ref.id, element);
  };
  element.add() // It return the current quantity
} CATEGORY "Customer" LABEL "Add product reference"
HELPTEXT "Provide a Physical Product reference as argument to increase quantity";

Example2

This example shows a method, which counts the number of requirements that are refined.

Satisfy the following prerequisites:

  • Create a template such as the Getting Started template with a specification folder as an input parameter.
  • Insert requirement specifications containing requirements in the specification folder.
  • Create a system scope to cover the requirements of the requirement specification by other requirements of another requirement specification.

Insert the following code in the OTScript tab of your template. This code creates a method named Number of refined requirements, which is added to the Customer category:

PACKAGE PLM;
METHOD `Requirement Group`.getDerivedRequirementsCount() -doc : {
     TMP reqSpecs := `rel_Requirement Group Content`.`to_Requirement Specification`;
     $CNT(reqSpecs.getAllRequirements()[$SOME(`rel_Derived Requirement`)])
} CATEGORY "Customer" LABEL "Number of refined requirements"
HELPTEXT "Get the number of requirements that are refined by other requirements";