DriveWorks Pro 15: Writing rules [send feedback...]

Writing rules

The rule editor is where you work with a rule, you can either type your rule directly in the rule editor, or use the function wizards and browsers on the rule builder to insert into the rule.

The rule is automatically colored and formatted by DriveWorks using settings which you can modify by clicking the Settings button on the command bar.

By default, if the rule is invalid, the background color changes to a light red, and if it is okay, then the background changes to a light green.

Rules, in the rule editor, can be formatted so they are easier to read.

Use the return key to place elements of the rule on separate lines and the tab key to make each element inline.

Underneath the rule editor are help and diagnostics tabs.

There are up to six tabs on the help and diagnostics section depending on the kind of rule being built:

  1. Help tab
  2. Values tab
  3. Steps tab
  4. Drill Down tab
  5. Comments tab
  6. Function Wizard tab

Where ever you can launch the rule builder you can build a rule. A rule defines how the parameter it is built on behaves.

A rule usually involves a function that evaluates some conditions and returns an answer, but it can also be a fixed or static value such as a number or text.

The sections below explain what can be entered into the rule builder.

Arithmetic Rules

Arithmetic calculations can be performed by the rule builder by typing directly in the rule editor.

Examples

Arithmetic calculation

Result
5 * (3500 - 500)

15000 - Multiplies 3500-500 by 5

(2900+55)/21477.5 - Divides 2900+55 by 2
200-20%180 - Subtracts 20% from 200
12^31728 - Raises the number 12 to the exponent 3

Math Operators

Variable Name

Value
+Add
-Subtract
*Multiply
/Subtract
%Percent
^Exponentiation

Floating Point Mathematics

When working with numbers that could calculate into many digits it is important to understand how DriveWorks works with these numbers.

This will avoid any unexpected results.

Please see the article Info: Floating Point Precision for more information.

Using Strings

Strings

A string is text and is required to be encased within quotes (i.e. " ").

The rule builder identifies text strings within a rule by color coding them (orange in the image below)

Examples

Text String

Meaning
"Hello World"Returns: Hello World

Joining Strings

Strings can be joined with other strings by including the ampersand symbol (&) between the strings.

Examples

Text String

Meaning
"Hello World" & "- How are you today?"

Returns: Hello World - How are you today?

Another method of joining strings is to use the Concatenate function.

Formatted Strings

Text strings can be formatted to include additional elements by using the @ symbol at the beginning of the string to be formatted.

At the point where the formatting is to be inserted use the @ symbol again and enclose the formatting within brackets ().

Examples

Formatted String

Meaning
@"Thank you for submitting your order, number @( DWVariableOrderNumber)"

Returns: "Thank you for submitting your order, number 12345"

The value 12345 is calculated from the variable OrderNumber.

@"The overall height will be @(HeightReturn + 2*DWVariableClearance)mm and the overall width will be @(DWVariableUnitAWidth + DWVariableUnitBWidth)mm"

Returns: "The overall height will be 2187mm and the overall width will be 1675mm"

The value 2187 is calculated from the value of the Height control added to 2 * the variable Clearance.

The value 1675 is calculated from the sum of the variables UnitAWidth and UnitBWidth

Strings can also be combined with functions, arithmetic and other references used throughout your project. See combining below.

Boolean Values

Boolean values are simply True or False values. These do not require to be encased within quotes.

Boolean values are generally used to control on or off parameters, such as a form control's visibility or a captured SOLIDWORKS feature.

Examples

Boolean Value

Meaning
TrueTurns the parameter or property ON
FalseTurns the parameter or property OFF
IF(CheckboxReturn = TRUE, TRUE, FALSE)Evaluates the value coming from a checkbox, and if TRUE will turn the parameter or property ON (TRUE), otherwise will turn the parameter or property OFF (FALSE).

Using Rule Builder Browsers

The browser tabs to the right of the rule builder provide access to Control values, Variables and Constants that can be used within rules. Other tabs will become available according to the rule type being built and the information captured.

The value of any Form Control property can be referenced within a rule. See How To: Reference Control Properties for more information.

Functions

Functions are used to calculate a value. They can be accessed by the following methods:

  • Autocomplete.
  • Functions Button.

Autocomplete

As you start typing, in the rule editor window, the autocomplete box will appear that displays a list of suggestions that match the characters entered.

The suggestions will include:

  • Functions
  • Variables
  • Constants
  • Tables
  • Form controls

A suggestion, from the autocomplete box, can be selected by using the up and down arrows on the keyboard and hitting return, or by clicking with the mouse.

Hovering over a suggestion will display the category that suggestion falls into. If the suggestion is a function a description of what the function does will be displayed.

Typing the start of a variable name within the function, filters the list to display all values that correspond to the entry.

Once a function has been selected,using autocomplete, rules insight offers further guidance on constructing the function.

Rules Insight

Rules Insight gives clear guidance on the function in use. The current required value is highlighted in bold, with a description of what the function expects for the argument.

Functions Button

The Functions button is located on left of the command bar in the rule builder.

Clicking the Functions button will open the Functions dialog.

The Functions dialog lists all functions that are available along with a description of what each does.

The list can be filtered by typing in the filter box at the top of the dialog.

To select a function

  1. Find the required function from the Function dialog
  2. Select the Function
  3. Click OK

Function Quick Pick List

At the bottom of the Functions Button is a drop down indicator. Clicking this will display a list of commonly used functions.

Once a function has been selected (either from the Function dialog or the Quick Pick list) list the Help and Diagnostics tabs (located underneath the rule editor) will switch to the wizard for the selected function.

The rule builder has many pre-defined functions, please see Common Functions for a complete list.

Combining

All elements that can be entered into the rule editor can be combined with each other to make a Dynamic Rule.

For instance a string can include an arithmetic calculation, which makes use of a function to dynamically change according to choices made on the user form.

To combine elements of a rule in this way the ampersand ( &) symbol is used.

Examples

Rule

Meaning
"Quote for " & ContactNameExistingReturn & ", reference " & Mid(CompanyNameExistingReturn,1,3) & 101 & 2 * OallLengthReturn

Returns: Quote for Mr. J. Tempest, reference DRI1014780

where ContactNameExisting is a control with the value Mr. J. Tempest.

", reference " is a string.

Mid(DWVariableCompanyName,1,3) is a function that return the first 3 letters of the value of the variable CompanyNameExistingReturn, to result in DRI.

101 is a fixed number.

2 * OallLengthReturn is an arithmetic calculation that multiplies the value in the control OallLength (2390) by 2, to result in 4780.

Nesting Functions

Functions can be inserted within other functions, this is known as nesting.

This allows for a very flexible and more Dynamic Rule.

To nest functions simply create the function to be nested at the place in the original function where a value is required.

Examples

Rule

Meaning
 IF( BoreReturn<4 , 1000 , IF(BoreReturn<8,2000,3000) )

IF function syntax: IF( Condition , Value if True , Value if False )

The nested function is in bold. The structure of the initial IF function is maintained i.e. the comma separating the two value fields and closing bracket ). In place of the value if false is an identically structured IF function.

TEXT( TODAY() , "mm/dd/yy" )

Text function syntax: TEXT( Value, Format )

The nested function is in bold. The structure of the initial TEXT function is maintained i.e. the comma that separates the Value and Format fields and the opening bracket (. In place of the Value field is the TODAY function.

DriveWorks projects allow nested functions to an unlimited depth.

There always should be a matching closing bracket for each opening bracket. The rules builder provides assistance for matching opening and closing brackets.

Bracket Matching

Examples

Rule

Meaning
IF( BoreReturn<4 , 1000 , IF( BoreReturn<8 , 2000 , IF( BoreReturn<12 , 3000 , IF( BoreReturn<16 , 4000 , IF( BoreReturn<20 , 5000 , 6000 ) ) ) ) )

IF function syntax: IF( Condition , Value if True , Value if False )

The nested functions are bold. The structure of the initial IF function is maintained i.e. the comma separating the two value fields and closing bracket ). In place of the value if false in each of the nests is an identically structured IF function.

VLOOKUP( IF( BoreReturn<4 , 1000 , IF( BoreReturn<8 , 2000 , IF( BoreReturn<12 , 3000 , IF( BoreReturn<16 , 4000 , IF( BoreReturn<20 , 5000 , 6000 ) ) ) ) ) , DwLookupBeamCalcs , 3 , TRUE )

VLOOKUP function syntax: VLOOKUP( Value , TableName , ColumnIndex , Matchtype)

The nested functions are bold. The structure of the initial VLOOKUP function is maintained i.e. the comma separating the value and TableName fields and Opening  bracket ). In place of the value field is a nested IF function.

Nesting multiple functions can make reading a rule difficult.

Consider using variables to break out the nests, see examples below and compare them to the examples above.

Examples

Rule

Meaning

IF( BoreReturn<4 , 1000 , DWVariableLessThan8 )

Where:

DWVariableLessThan8 = IF( BoreReturn<8 , 2000 , DWVariableLessThan12 )

DWVariableLessThan12 = IF( BoreReturn<12 , 3000 , DWVariableLessThan16 )

DWVariableLessThan16 =  IF( BoreReturn<16 , 4000 , DWVariableLessThan20 )

DWVariableLessThan20 = IF( BoreReturn<20 , 5000 , 6000 )

When the condition BoreReturn<4 is False it will return the result of the variable LessThan8.

When the condition of variable LessThan8 is False it will return the result of the variable LessThan12.

and so on....

VLOOKUP(  DWVariableBoreLookup , DwLookupBeamCalcs , 3 , TRUE )

Where:

DWVariableBoreLookup = IF( BoreReturn<8 , 2000 , DWVariableLessThan12 )

DWVariableLessThan12 = IF( BoreReturn<12 , 3000 , DWVariableLessThan16 )

DWVariableLessThan16 = IF( BoreReturn<16 , 4000 , DWVariableLessThan20 )

DWVariableLessThan20 = IF( BoreReturn<20 , 5000 , 6000 )

Will lookup the value of variable BoreLookup

When the condition of variable BoreLookup is False it will return the result of the variable LessThan12.

and so on....

Special Variables

DriveWorks has built in variables known as Special Variables that can be used in rules.

The special variables are found in the Rule Builder from the Quick Text drop down. Once selected the special variable name will appear in the rule editor.

A full list of all available special variables can be found here.

DriveWorks Tech Tips Portal

Table Filtering

The TableFilter function allows a Data Table to be filtered using other form controls (such as a text box or combo box) so that only the relevant items are displayed.

View all Tech Tips

DriveWorks Tech Tips Portal is available to DriveWorks Pro customers with an active subscription and support contract.

Tech Tips provide cut down projects that highlight specific functionality for faster and more effective learning.

To access the portal:

  1. Go to https://hub.driveworks.co.uk/tech-tips/
  2. Login with your DriveWorks Pro account credentials, if asked
  3. Click the Visit Tech Tips Portal button for access

The portal provides a search facility, start typing the name of the Tech Tip (as indicated above) to display the Tip you require.

Table of Contents