• Informed Design
  • Inventor

Codeblocks - understand data types

Understand data types in Codeblocks, such as Number blocks, Text blocks, True False blocks, and List blocks, as well as how to match the expected data type to each block.


Step-by-step guide

Different code blocks expect different data types. Attempting to snap the wrong data type to a code block will not work, so it is important to understand the different data types.

In this example, there are four code blocks relating to a Height parameter, and each expects a different data type:

  • The first Nominal Wall Height parameter block is set to values, and expects a list or collection of data. The list can be composed of any data type, and in this case, includes two numeric blocks, 8 and 10.
  • The second block is set to value and expects a numeric data type, such as 8.
  • The third is set to label, which expects a Text data type. In this case, a Text block with the word “Length” is used.
  • The last block is set to readOnly, which sets a Parameter to be editable or not editable in the form. This block expects a True False data type.
  • On the canvas, four examples of parameter blocks that require different data types based on the function selected.

Modify each block to see how it impacts the form.

  1. For the Values block, click plus (+) to add a new list member, Duplicate a Number block, and input a value of 7.
  2. Click Update form, and the new value appears in the Length parameter drop-down.
  • In the values block, a value of 7 added to the list, and in the form, the value shown in the expanded Length drop-down.
  1. In the Value block, change the number to 7. Click Update form, and the new value appears in the Length input.
  2. For the Label block, change the text to “Hello World”. Click Update form, and the label updates in the form. Change the label back to “Length”.
  • In the parameter blocks, the value and label changed for this example, and in the form, the input and label updated to match.
  1. Change the Read-only block to be true. Click Update form to make the parameter read-only. Change the value back to false and click Update form to make the parameter editable again.
  • The True False block set to be true, and the form updated to show the parameter as read-only.

To further understand how parameter blocks handle data type changes:

  1. Add a Nominal Wall Height value equals parameter block and add a Number block set to 8.

In addition to Number blocks, the Parameter block also accepts mathematical equations:

  1. Add an Equation block, move the 8 to the first position, and then set it up to subtract 1. Connect the block to the parameter.
  • The Value parameter block, with an added Math block.

To see what happens when the wrong data type is added to a parameter block:

  1. Change the drop-down from value to the plural, values.

The equation block is rejected because a parameter set to values expects a list, not a numeric data type.

  1. Snap the Equation back to the parameter block, and it is rejected again. Try a Number, and it is rejected as well. A Text block is also rejected. The block will not accept data types that may generate an error.
  • On the canvas, the Values parameter block and the rejected data types, including the Equation block, the Number block, and the Text block.

Recall that the Values parameter block expects a list.

  1. Add a Create List With block. This data type is accepted.
  • The Values parameter block with the accepted Create List With block, and below, the rejected data types.
  1. Snap each of the rejected blocks to the Create List With block, and all are accepted.
  • In the Values parameter block, the Create List With block, with the accepted Text, Equation, and Number blocks.
  1. Change the parameter block to a Label block to see that it rejects the List data type, as well as a Number block.
  2. Add a Text block, and it is accepted, because the Label requires text for the form label.
  • The Label parameter block with the accepted Text block, and below, the rejected Create List With and Number blocks.
  1. Change the block to Read-only and test the different data types.

In summary, different code blocks expect different data types. The program prevents snapping incompatible data types to a code block. The general code block data type categories are text, numeric, lists, and true false.

Was this information helpful?