• Informed Design
  • Inventor

Codeblocks - use the If block

Use the If Then and If Then Else blocks with comparison evaluators to define logic in Informed Design Codeblocks rules.


Step-by-step guide:

Logic statements are an essential part of creating code block rules. In this example, use Logic code blocks to evaluate the height of a wall to ensure that if the wall height equals the opening height, then the opening height will be reset to a specified lower value.

  1. In the Rules workspace, from the Logic blocks library, add the If Do and Comparison blocks to the canvas.
  • With the Inventor interface open in the background, the Rules workspace, where the If Do and Comparison blocks are highlighted in the expanded Logic blocks library.
  1. Assemble the blocks to create the framework of the conditional statement.
  2. Add the Wall Height variable and the Nominal Wall Height value parameter block to the If portion of the statement.
  • The If Do block, with the parameter and variable code blocks added to the If portion of the statement.
  1. Add a parameter block to the Do portion of the If Do block and set the parameter input to Opening_Height.
  • A parameter block added to the Do portion of the If Do statement, with Opening Height being selected in the input drop-down.

Add a Math Number block to the statement and enter the value 84. When the If portion of the statement is true, the opening height will be reset to this specified lower value.

  • A Math Number block added to the Do portion of the statement, with a value of 84 entered.
  1. Right-click the existing block that sets the opening height list and select Duplicate.
  2. Add the duplicate block to the If Do block below the opening height statement.
  3. In the parameter choice list, click the minus sign (-), remove 96 and replace it with 84.
  • In the If Do block, the added Create list with statement shows a single value of 84.

An If Do ElseIf block can also be used to evaluate additional conditions.

  1. In the existing parameter choice list, click the plus sign (+), and enter a value of 12.
  • In the existing Parameter choice list, an additional value of 12 added and highlighted.
  1. In the If Do block, next to If, click the plus sign (+). This expands the block to include an ElseIf statement.
  • The If Do block, with the hand cursor pointing to the plus sign and an If Do ElseIf block added.
  1. Duplicate the parameter blocks from the existing If block and add them to the new ElseIf and Do block areas, respectively.

Next, add the desired logic:

  1. In the ElseIf portion of the statement, enter a value of 10
  2. In the Do portion, enter a value of 96.
  • The applicable parameter blocks are duplicated and added to the If Do ElseIf statement, and the entered values of 10 and 96 are highlighted.

Add as many ElseIf statements as needed, and repeat the steps of duplicating and updating the parameter blocks to create the required logic.

  1. Expand the Logic blocks library and note that there is also an If Do Else block.
  • The expanded Logic blocks library, with the If Do Else block highlighted.
  1. Replace the If Do block with the If Do Else block.

The Else statement specifies what should happen when the If statement is not true or when none of the If Else statements evaluate as true.

  • The If Do Else block with parameters and values applied for this example.
  1. In the Logic blocks library, select the Comparison code block. Expand the input drop-down to view the list of standard equality operators, shown below.
  • Next to the blocks library, the Comparison block, with the drop-down expanded to show the available options: Equal, Not Equal, Less Than, Less Than or Equal To, Greater Than, and Greater Than or Equal To.
  1. Under Logic, select the Operator code block. Expand the input to see that it contains the And, and Or operators.
  • The Operator block drop-down expanded to show the available options.

The And operator evaluates the statement as false if any condition is false. Conversely, the Or operator evaluates the statement as true if any condition is true.

  1. Add the And Operator to the If Do statement.
  • The If Do block, with the And statement added.
  1. Duplicate the parameter block containing the equals comparison and add it to the And statement.
  2. Right-click and select External Inputs to wrap the code block to better fit on the canvas.
  3. Change the first comparison operator to Greater Than (>) and change the second to Less Than (<).
  4. Update the Do statement block to evaluate the correct value of 96 when the wall height is greater than the first value of 8, and less than the second value of 12.
  • The updated If Do block, with the code block wrapped and the applicable operators and values added.

In summary, If Do code blocks with Else and ElseIf statements, combined with operator code blocks, can be used together to create powerful logic rules, allowing you to evaluate a robust set of logic.

Was this information helpful?