Create an External Rule
You can create rules defined at the Library level: They are
called by their names, and a list of arguments corresponding to their
signatures.
-
Click
Add KML Rule
to add a new
rule to the Library.
The Create new KML Rule dialog box
opens.
-
Type the name of the Rule and click
OK.
The rule you created appears in the
tree
below the Rules node.
-
Double-click the rule to edit it.
The KML Rule Editor opens.
-
Enter the rule script:
-
Double-click the
<Add new argument> field and enter
the name of the argument,
iTemplate in our example.
-
Double-click the
Type field and select the
Feature type.
-
Double-click the In/Out field and
select
In.
-
Repeat the above three steps to create an
iOutputsName argument of
List type, and select In.
-
Create an argument called
oOutputs of
List type
in Output.
The arguments are created.
-
Enter the script body:
let i(Integer)
i = 1
if iOutputsName <> NULL
{
for i while i <= iOutputsName.Size()
{
oOutputs.Append(iTemplate.GetAttributeObject(iOutputsName.GetItem(i)))
}
}
-
Click
OK.
The external rule is created.
Create a Local Rule
You can create local rules that enable you to access the
attributes and the children of the current concept.
In the
Know-how Apps Logic Editor, enter the
following script:
Rule "CreateTableChildren"
{
/* This rule creates the Table Top and Foot children and passes on the inputs when possible */
if tableGeometry == "Round"
tableTop = new("MyRoundTableTop","tableTop",this,2cm,topReference)
else
tableTop = new("MyRectangularTableTop","tableTop",this,2cm,topReference)
tableFoot = new("MyTableFoot","tableFoot",this,tableHeight-2cm,footRadius)
}
The internal Rule is created.
A name (CreateTableChildren in the above example) can be attributed to the rule to make it easier to locate errors at instantiation. This name is optional.
Create an Event-Triggered Rule
You can create Event-Triggered Rules: On Init Rules and On
Valuation Rules. On Init Rules can be used to do a pre-treatment on KML Objects
instantiated from the Concept. They are executed as soon as the KML Object is
created. On Valuation Rules can be used to do a post-valuation treatment on a
set of attributes. They are executed only when all inputs and specified
attributes are evaluated on an object.
-
To create an On Init Rule, enter the following script into the
Know-how Apps LogicEditor:
Rule on Init
{
/* Here the initialization rule is used to provide default values to the attributes */
tableHeight = 1m
footRadius = 2cm
tableGeometry = "Rectangular"
}
-
To create an On Valuation rule, enter the following script into
the
Know-how Apps Logiceditor:
/* This rule will be executed only when Object and a are evaluated */
Rule on Valuation Object, a
{
let b(Integer)
c = b / 2
Message(“Object has name #, a has value # and b/2 = #”,Object.Name, a,c)
};
You Rules are created.
Use the On Condition Keyword in Rules
The On Condition keyword is used to execute a rule dynamically depending on predefined conditions. This keyword lets you define different behaviors for a same concept, with different inputs that may not all be used. It operates on Rules only. The inputs required for executing a condition are asked sequentially and the inputs for the selected rules are then determined. Concept FuelType : BaseConcept
{
Object : VoidType;
Attributes
{
Inputs
{
String engineType { "Diesel", "Gas" };
Integer productionYear;
}
Outputs
{
String fuelType { "Diesel", "Gas", "Ethanol"};
}
}
Rules
{
Rule on Condition engineType == "Diesel"
{
fuelType = "Diesel"
}
Else if engineType == "Gas" AND productionYear > 2000
{
fuelType = "Ethanol"
}
Else
{
fuelType = "Gas"
}
}
} In the above example, if the engine type is "Diesel" no value is required for "productionYear" and the first rule is launched. If another engine type was selected, the "productionYear" is valuated.
Create a Rule Integrating a Knowledge Dialog
When editing a KML Library, you can add a Dialogs subpart to
the Rules section of your Concept.
The syntax is the following:
Rules
{
Dialogs
{
DialogName ( dialogAttr1 = conceptAttr1;
dialogAttr2 = conceptAttr2;
);
...
}
}
...
Note:
The Knowledge dialog you want to use is identified by its name.
Dialogs are retrieved from the Know-how Apps
component of the library and from all
its prerequisites components. The attributes of the Dialog are bound to the
Concepts attributes (for example conceptAttr1 will be bound to dialogAttr1).
The fact that they are declared as input or output in the Dialog is checked by
the KML engine and the information is used to determine if the dialog is an
attribute evaluator or if this attribute must be evaluated beforehand.
-
Create your dialog in the
Know-how Apps User Experience app.
-
To create a rule integrating a dialog, key in the following
script into the
Know-how Apps Logic Editor:
At runtime, when the engine detects that it has to execute a
dialog to evaluate one or several attributes it does not display the standard
Instantiation dialog box and displays the dialog box you created instead. If
the instantiation contains only dialog evaluators, you may not see the standard
KML instantiation dialog box at all because it will be fully overridden by
Knowledge dialogs.
When the engine executes a dialog, it :
- Copies the values of all KML attributes into their bound
Dialog variable
- Executes the dialog.
When the execution is done, the attributes that were treated at
the first step are valuated from their bound variables. This means that all
value changes during the execution of the dialog is propagated to the KML
attributes, even if the attribute is an input.
To view an example, import the KMLSample.3dxml file located in
win_b64\startup\Knowledgeware\KMLSamples\Sample1
in the installation folder.
Creating a Rule Containing a Filter
You can define filters to apply to inputs in your KML script.
In the Rule section, you can insert a filter block and determine which inputs
are filtered by the KML rule thus making the instantiation easier.
Filters can be used to:
- Narrow down the possibilities of selection. You can for example
ensure that a selected curve has a minimum or maximum length.
- Slightly modify the selection (see script below).
The aim of the filter is to define a specific external rule called
when selecting an attribute at instantiation time. This rule takes as input the
current selection and returns as output a filtered selection which can be:
- NULL if the current selection is not suitable.
- The selected object if the current object is suitable.
- Another object if the selected object needs to be replaced by
another one (Occurrence replaced by Reference for example).
In
the script below, the rule is executed when selecting a feature as input for
destination and automatically filters the selection of an occurrence or
instance in its corresponding reference.
-
Enter the script below:
Concept MyProductCreator : BaseConcept
{
Object : VPMInstance = new(“VPMReference”,”MyCreatedRefInst”,destination);
Attributes
{
{
Inputs
{
VPMReference destination;
}
}
Rules
{
Filters
{
GetReferenceFromObject(destination);
}
}
}
-
Define the KML rule with a specific signature:
GetReferenceFromObject(iSelection : Feature, iObject:
BaseConcept, oFilteredSelection : Out Feature) .
{
let refInst(VPMInstance)
let refOcc(ProductOccurrence)
if iSelection->IsASortOf(“ProductOccurrence”)
{
refOcc = iSelection:ProductOccurrence
oFilteredSelection = iSelection.Reference
}
else
{
if iSelection->IsASortOf(“VPMInstance”)
{
refInst = iSelection:VPMInstance
oFilteredSelection = refInst.Reference
}
else
{
if iSelection->IsASortOf(“VPMReference”)
{
oFilteredSelection = iSelection
}
}
}
}
The filter is created.
|