Home Search

DriveWorks Solo 19
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.

When typing Functions in the Rule Builder rules insight can be closed by hitting the Escape key on the keyboard.

Rules insight will return when an argument is required, hitting Escape again will close rules insight.

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

Writing Rules

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

Strings

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

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

Examples

Text String

Meaning
"Hello World"Returns: Hello World

Including Quotation Marks

When quotation marks are required in the resulting string, additional double quotes are required for each quote.

Examples

Text String

Meaning
"""Hello World"""Returns: "Hello World"
"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).

Functions

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

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

Bracket matching allows you to see where brackets open and close. Easily identifying where a rule could be failing.

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.

The available special variables are listed below:

Specification ID

Name: DWSpecificationId

Every time a project is run in DriveWorks, it is allocated a guaranteed unique incrementing number called a specification id, which is combined with the name of the project to give the running project its specification name.

The Specification Id and Specification Name are used in DriveWorks in various ways, e.g.:

  • Whenever a running project is finished, a folder is created which is named after the specification name in a folder called "Results" in the same folder as the project file.
  • By default, new models are created with the same name as their originals but suffixed with the specification name.
You can use the Specification Id and Specification Name in your own rules by using the Quick Text button on the Rules Builder.
The Specification Id and Specification Name are made available to the running project in two Special Variables called "DWSpecificationId" and "DWSpecification" respectively.
DWSpecificationID begins at 1 and has a range of approximately 2 billion.

Examples

Rule

Meaning
DWSpecificationId

Will result in 9999 while administering a project.

Will result in the next available number once a project is running, e.g. 1

TEXT(DWSpecificationID,"0000")

Will ensure the result contains at least 4 digits, e.g. 0001

This will NOT truncate the DWSpecificationID when the range goes above 9999 but will always include at least 4 digits.

Specification Name

Name: DWSpecification

Every time a project is run in DriveWorks, it is allocated a guaranteed unique incrementing number called a specification id, which is combined with the name of the project to give the running project its specification name.

The Specification Id and Specification Name are used in DriveWorks in various ways, e.g.:

  • Whenever a running project is finished, a folder is created which is named after the specification name in a folder called "Results" in the same folder as the project file.
  • By default, new models are created with the same name as their originals but suffixed with the specification name.
You can use the Specification Id and Specification Name in your own rules by using the Quick Text button on the Rules Builder.
The Specification Id and Specification Name are made available to the running project in two Special Variables called "DWSpecificationId" and "DWSpecification" respectively.
DWSpecificationID begins at 1 and has a range of approximately 2 billion.

Examples

Rule

Meaning
DWSpecification

Will return the combined name of the project and the SpecifactionID