Workspace 6.21.5
Understanding Array Inputs

Workspace operations often require not individual inputs of a particular type, but an unbounded number. For example, to concatenate two strings together, we might create an operation that has two QString inputs and one QString output, where the output is the result of the two input strings concatenated together. But what if we wanted to contatenate three strings? Or four? We could either:

  1. Chain many concatenation operations together in our workflow. This could be time consuming.
  2. Create an operation that knows how to concatenate any number of strings together.

Clearly, the second option above is the most useful. Workspace allows us to do this through the use of Array Inputs; inputs that provide a whole array of input data to the operation they are attached to. In fact, for the case of concatenating strings, such an operation already exists; the ConcatenateStrings operation:

The ConcatenateStrings operation with its "Strings" array input.

If we look closely at the ConcatenateStrings operation above, we will see that the "Strings" input is decorated with four small dots. These dots indicate that the input is an Array Input, and thus it can be comprised of any number of data elements.

Adding elements to an Array Input

There are three ways to add an element to an array input:

  1. Right-click on the array input and select the "Add input element" option in the context menu.
    Adding an input element to an array input
  2. Double-click on the array input. This will automatically add a new element.
  3. If our element's data is to come from another operation, we can simply drag-and-drop a connection onto the element as we would when we create an ordinary connection. Workspace will automatically create a new array input element for us, and attach our new connection to it.

Each of the above options is equivalent - whichever you use is a matter of personal preference. Once you've added elements, you can identify them on the workflow as the sub-inputs of the array input.

The Strings array input with two elements, shown as indented elements under the Strings array input

Deleting elements

To delete an array input, simply right click on it and select the "Delete input element" option in the context menu. If the element already has a connection, you will be prompted as to whether you wish to delete it.

Deleting an input element

Editing elements

Once you've created array input elements, as with ordinary inputs, you are able to edit the data assigned to unconnected elements using the Operation Editor. Simply click on the operation itself, and you will see the inputs in the OperationEditor as we can see from the ConcatenateStrings screenshot below.

Editing array input elements

Re-ordering elements

In many cases, the order of elements in an array input is significant. For example, in the case of the ConcatenateStrings operation, the order of elements in the Strings input indicates the order that the strings will be contatenated together. If we put the strings in a different order, we will result in different output strings. If we wish to know which index a particular element is, we can hover over it to see a tooltip.

Tooltip showing the index of a particular array input element

It also is possible to re-order array input elements. To do this, right click on the array input and select "Re-order inputs".

Re-ordering array input elements

You'll then be presented with a dialog where it is possible to control the exact order of the input elements. The dialog shows the source output, source operation and data for each input element, as can be seen in the screenshot below.

Controlling the order of array input elements

To change the order, drag and drop the row to where you want it. The indices will be reassigned in order when the dialog box is closed.

Reordered array input elements