Refer to your methodolgy for creating the load Rule.
Create the following new Rules:
Table Design Rule |
|||
Name: |
maxSpacing |
Special Instructions: |
|
Type: |
Number |
|
|
Flags: |
Cached, Parameter |
Category: |
Inputs |
Value: |
48 |
Table Design Rule |
|||
Name: |
thickness |
Special Instructions: |
|
Type: |
Number |
|
|
Flags: |
Cached |
Category: |
Calculated |
Value: |
if (this.load < 300){ return 3 } else { return 6 } |
As with the custom "Inputs" category, you will need to manually add the thickness category for "Calculated".
The value in the thickness rule above is an example of the use of "this" in kBridge expressions. "this.[name of rule]" refers to the value of a rule that is part of the current Model's rule set.
In this case, since we're in the context of the MyTable model, you could parse the thickness rule as: "If the value of the load rule created for this Table is less than 300, then the thickness [of whatever Model it will be applied to] is 3; if the load value is more than 300, then the thickness is 6."
CONCEPT: LOGICAL RULE – If/ThenMost of the Rules we use for this simple table example are either constants, simply a number, or a simple mathematical relationship using the mathematical operators +, -, *, and /. However, the thickness Rule above introduces a new type of Rule expression, called a logical operation. In this case it is an if/then type of logical operation, but there are other logical expressions that can be used. For more, see logical expressions.
A simple form of the If/then syntax is as follows: If (<logical expression that returns true or false>) { return <expression if true> } else { return <expression if false>
[Note: whitespace and some word spacing (not all) is ignored in the JavaScript language, so you may structure your code any way you like. What is shown above is the traditional structure used by most Rule writers for an if-then expression.]
|
Table Design Rule |
|||
Name: |
numberOfLegs |
Special Instructions: |
|
Type: |
integer |
|
|
Flags: |
cached |
Category: |
calculated |
Value: |
Math.ceil ( (this.length / this.maxSpacing) + 1 ) |
Math.ceil() (note that it's capital "M") is a JavaScript function that returns the greatest integer greater than or equal to a given number.
Table Design Rule |
|||
Name: |
numberOfSpaces |
Special Instructions: |
|
Type: |
number |
|
|
Flags: |
cached |
Category: |
calculated |
Value: |
this.numberOfLegs - 1 |
Table Design Rule |
|||
Name: |
legSpacing |
Special Instructions: |
|
Type: |
number |
|
|
Flags: |
cached |
Category: |
calculated |
Value: |
( this.length - this.thickness ) / this.numberOfSpaces |
Extra credit: What does the result of these Formulas tell you about the configuration of the Table? (LegSpacing is the distance between sets of legs. NumberOfLegs is the number of leg pairs. NumberOfSpaces is the number of spaces between legs.)