Home Search

DriveWorks Pro 21
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:

Help tab

When building Model or Drawing rules the help tab displays useful information about the type of rule you are building.

This enables you to quickly see what the result of the rule needs to be to achieve the desired outcome. For example when building a rule for a model feature the rule needs to be "Delete" or "Suppress"

The help tab is not shown for control properties, variables or document rules.

Values tab

The values tab shows any variables and control properties that are being used in the rule, along with their current values, and the current result of the rule.

Steps tab

Shows the steps taken to evaluate the rule along with the value of the rule at each step.

Drill Down tab

The drill down tab provides the information used in the values and steps to be analyzed by expanding the rule at each stage it takes to get to the result.

Color Meanings

DriveWorks color codes various items it recognizes.

The colors used are the inverse of those applied in the Display Item Settings. The color applied to the Foreground Color setting becomes the background color in Rule drill Down.

The result (if applicable) of each item is also shown within the background color.

Display ItemDescriptionDefault Background ColorPreview
FunctionThe color of any DriveWorks function used in the rule editor.
ReferenceThe color of any Constant, Variable, Special Variable, Table, Control value or hierarchical reference used in the rule editor.
BooleanThe color of any TRUE or FALSE value used in the rule editor.
NumberThe color of any numeric value used in the rule editor.
StringThe color of all strings within quotes " " used in the rule editor.
OperatorThe color of any valid operator (+, -, *, /, <, >, =, etc.) used in the rule editor.

Comments tab

The comments tab provides an area where notes about the rule can be entered.

The comments tab will be headed Comments (Empty) if a rule has no comments.

When a comment is changed a revision is created. See Revisions for more information.

Please Note

Comments are stored in the Project file, this is copied and loaded with each Specification.

When using Child or Hosted Specifications, each Specification will copy and load its own Project file simultaneously.

We recommend keeping each comment to an absolute minimum, so performance is not affected.

For example:

100 characters used in a comment adds between 0.1Kb and 0.4Kb to the size of a Project (and Specification) file.

If this occurs in 250 rules, the file size could increase by 100Kb.

If 10 Child or Hosted Specifications are running the excess caused by the comments is now 1Mb.

If this is run through DriveWorks Live where 10 users are running the 10 Child or Hosted Specifications, this is now 10Mb extra that the Server needs to process.

Function Wizard tab

The Function Wizard tab appears when a function is selected from the Functions button.

The name of the tab changes to the name of the function selected.

The wizard for each function provides assistance in providing the necessary information for the function.

See Common Functions for more information on the functions that are available.

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

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.

Prefixes

DriveWorks will recognize some strings (formatted within <> symbols) as prefix strings and will replace them with specific values when they are evaluated.

The evaluation takes place when a Specification is transitioned, during the running of a Specification, and not during the building of the rule.

Prefix strings will only be evaluated in areas where the expected result is a file path.

For example the Default File Name property of the Upload Control expects a full file path.

Prefixes must be declared at the start of the string.

Examples

Strings are not case sensitive
Prefix String DescriptionPossible UsesExample
<Project>Inserts the full path to the Project location.Default File Name

FSGetFullPath

"<Project>\Uploads\" & DWVariableFileName

FSGetFullPath("<Project>")

<Specification>Inserts the full path to the Default Specification folder.As above"<Specification>\Uploads\" & DWVariableFileName

FSGetFullPath("<Specification>")

<SpecificationMetaData>Inserts the full path to the meta data folder created for each Specification.As above"<SpecificationMetaData>\Uploads\" & DWVariableFileName

FSGetFullPath("<SpecificationMetaData>")

<GroupContent>Inserts the full path to the Group Content folder.As above"<GroupContent>\Uploads\" & DWVariableFileName

FSGetFullPath("<GroupContent>")

Directives

DriveWorks will recognize some strings (formatted within <> symbols) as directive strings and will replace them with specific values when they are evaluated.

The evaluation takes place when a Specification is transitioned, during the running of a Specification, and not during the building of the rule.

Examples

Strings are not case sensitive
Directive StringDescriptionPossible UsesExample
<Master:Name>Inserts the master name of the component it is applied toFile Name RuleSee link in Possible Uses
<Master:Path>Inserts the master path of the component it is applied toRelative Path RuleSee link in Possible Uses
<Replace>Replaces the component it is applied to with another component set (that has been captured in DriveWorks).File Name Rule

Instance Rule

See link in Possible Uses
<ReplaceFile>Replaces the component it is applied to with another file (that has not been captured in DriveWorks).File Name Rule

Instance Rule

See link in Possible Uses

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 arrow at the bottom of the Functions button will present a list of commonly used Functions.

Selecting one of these will open the Function Wizard tab at the bottom of the Rule Builder.

Clicking the Functions button will open the Functions list.

See Common Functions for more information on the functions that are available.

The Functions list shows 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.

The filter will match on Function Name and Description.

For example, typing tangent into the filter will display all Functions that use tangent in the description.

To select a function

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

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://my.driveworks.co.uk/learn/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.

A Dynamic Rule is a rule whose result can change.

Referencing any form control value, variable or function within a rule makes it dynamic and will automatically be re-calculated, whenever a control is changed, during specification.