Rules basics

Home / Rules & functions / Rules basics
TOC Script

Rules Basics

This section explains how to add logic to your model. This can be done in two ways:

  • Create a rule manually
  • Use the ‘expression builder’ to build rules
  • Add a rule via a wizard

Create a rule manually

Standard rule

Using rules, your model can be extended with business intelligence.
To add a rule, you have to go to the Rules tab.

In this tab, you can add a Rule to the model by right clicking on the 'Rules' element, and choose 'New Rule'.

A new rule is added:

A rule contains the following fields:

  1. IdIdentification of a rule
  2. Description = Description of a rule
  3. Execute at startup = Determines whether this rule should be executed when the model starts. This can be turned off to improve performance.
  4. Condition = Determines whether the rule will be executed
  5. Implication = The logic that will be executed.

Explanation by using an example:
Let's say we need a rule filling the default value of property2 with the value of property1, but only when property1 has a value. In the picture below the example to do this in e-Con. 

Condition:    
The property: ‘CreateaRule.Property1’ must be not equal to empty.

Implication:  
The default of ‘CreateaRule.Property2’ will be set equal to the value of ‘CreateaRule.Property1’

To keep your rules organized, you can use Groups. Adding a group can be done in the context menu as well:

After giving the group a useful name, you can drag and drop existing rules to the group, or add new rules to the group:

Validation rules

You can also add a validation rule. A validation rule displays a message when the condition is met. For example, while configuring a door, the width of any windows in the door may not exceed the width of the door itself.

To add a validation, right click on the location you want to add the rule and choose 'New Validation':

The User Interface of a validation rule is slightly different:

A validation rule has the following fields:

  1. Id: Identification of a rule
  2. Description: Description of a rule
  3. Error or Warning: Error: after the message is displayed, the previous value is reset. Use this if the value is not possible at all or warning: although the value is incorrect, it will not be reset.
  4. Condition: Determines when the message will be displayed
  5. Message: The message to be displayed

The following validation rules is created to validate the width of any windows in the door:

Translate vallidation rules:

The easiest way to translate the message is to set up a reference in the model. Name it for example ‘Translations’ and make it invisible and constant. Create for the various messages you need a property and define the message in the label of that property. In case the label will be too long, you can also use multiple properties for one message. 

1111

The label of this property can be used in the vallidation rule as showed below. Labels can be easily translated via the label management in e-Con Studio. There’s more about this On the page ‘how to translate my model

1112


Expression Builder

The Expression Builder contains all kind of logic that is necessary to build up a rule. It is divided in several categories to make it easy to find. For most items, an explanation and an example is available as well.

You can open the Expression Builder by clicking the Expression Builder icon in the view toolbar, or in the View menu. You can also use the shortcut <Ctrl> + E.


The following categories are available:

  • Arithmetic: As in the name, math blocks are available in here
  • Attribute: In here all property / reference attributes are available, such as default, enabled, et cetera.Note: you can also drag and drop an attribute including the property from the Object Explorer.
  • CollectionWhen working with collections, this category can be useful. An example of an collection is the @options attribute of a member.
  • Comparison: Helpful blocks for comparison. This can be used in an if-statement, or in the condition of a rule. 
  • Conditional: Blocks for a conditional rule. 
  • Constant: Constants that can be used in your model. Some items are examples of certain functionality.
  • Format: Add a formatting to a property.
  • Local Variable: Local variables can be used in a rule. After the rule is executed, these variables are disposed. You can use these for example in complex calculations. There are two items available per property type: one including initialization of the variable, one without.
  • Functional:All functions that are available for your model. Note: after adding a library to your model, any functions that are found in the library are added as well.
  • LoopLogic for looping through a collection, for example an array.
  • LogicalLogical statements
  • Option attributeAttributes of options can be found in here
  • Statement: In here statements can be found, like an assignment (A = B)
  • Style: Use this category for editing styles in a rule.
  • Task:In here all available tasks are listed. A task can be added to a button. Note: the first item of the list can be used to assign a task to a button. The second item of the list can be used to assign multiple tasks to one button. The other items are the actual tasks.

To add logic to your rule, set the cursor on the location where the logic should be added. Select an item from the expression builder and click the Copy button or double click at the expression name. Notice also that it’s also possible to use a wizard that will help you creating the rule with the chosen expression. More about this helpful functionality can found in the next subpage.

This is the result:

After copying the logic, you should replace the '<expr>' blocks. You can add one of the following:

  • Property / Reference
  • Attribute of a Property / Reference (for example: Property1@default)
  • Another expression from the expression builder.

Add a wizard

While editing the structure of an e-Con model, you might want to add business intelligence. For the most common scenario's, a wizard is available. In this paragraph the use of wizards is explained. How to use the available kind of wizards is explained at other pages. Clicking the name of the wizard in the list below will navigate you to the page with more information of the chosen wizard.

You can start a wizard by clicking the button 'Fx' in the properties grid:

After clicking the 'Fx' button, the wizard window pops up. You have to choose the wizard that fits your scenario. The wizard are explained in more detail in the subpages of this topic.

After you finished a wizard the button in the property grid turns aqua blue: This tells you that a wizard is already used to fill this property. You can always run the wizard again and adjust values.

Each wizard generates a rule containing the business intelligence. You can find these so called 'Wizard Rules' in the rules tab:


As you can see, a folder is created per wizard. Let's examine a specific rule:

Since you should edit these rules by the wizards, all wizard rules are read-only. However, if you still want to edit the rule, you can click on the 'Click here to edit' link. This will give you a warning, since you cannot run the wizard anymore after continuing. Editing a wizard rule might be useful if the wizard does not fully apply to your requirements. You can use the wizard to create the 'basic' of the rule, which you can later adjust to your needs.

Expression Wizard

The Expression Wizard creates a rule using a certain function from the Expression Builder. The Expression Wizard can be selected after starting the wizard screen using the 'Fx' icon on properties. The Expression Wizard can also be started after selecting a function on the Expression Builder. The output will be added to the current rule. In this example, the Expression Wizard is used for the Max function in the Expression Builder.

First add a new rule to the model.

Select the Max function in the expression builder.

Since a rule is selected in the e-Con model, the buttons Start Wizard and Copy are enabled. The Copy wizard can be used when the modeler manually creates a rule. Click the Start Wizard button to start the Expression Wizard.

In the Expression Wizard, the arguments can be entered. Using the add/remove buttons below, you can add more optional parameters:

Clicking the go button will add the result to the selected rule.


Related topics

Browse categories