Table of Contents
For Each and End For Each
These commands can be used to execute pipeline commands multiple times for each item in a list of items.
The resulting loop is not identical with a “for loop” or “do loop” in a programming language because the items must be explicitly defined as ITEMS in the command. This has some powerful benefits, however, since it allows users to “loop” through disconnected items or strings as easily as through a structured list.
Command Syntax
The full pipeline command syntax for For Each and End For Each in Visual3D is below:
For_Each /ITERATION_PARAMETER_NAME= ! /ITERATION_PARAMETER_COUNT_NAME= ! /ITERATION_PARAMETER_COUNT_BUFFER= ! /ITEMS= ;
End_For_Each /ITERATION_PARAMETER_NAME= ;
Command Parameters
The following table shows the command parameters that can be used to define the command and their descriptions:
| Parameter | Description |
| Iteration Parameter Name | The name of the loop itself, which must be used in the matching End_For_Each. Doubles as a pipeline parameter to access the item (see below) for the current iteration. |
| Iteration Parameter Count Name | A pipeline parameter name (ex. INDEX_COUNT) can be placed here. Referencing the parameter INDEX_COUNT will return the iteration number. The result will be 1 based, so the first loop through will return 1, the second will return 2, etc. Available as of version 5.02.17. |
| Iteration Parameter Count Buffer | Allows for multi-character counters when dynamically building strings, (e.g., file names) |
| Items | The items that will be looped through. Within the loop the Iteration Parameter Name can be used to access the current item. |
Examples
Example: Compute the GLOBAL mean value of a signal for each of 3 tags
This example computes the GLOBAL mean value of a signal for each of 3 tags (TAG1, TAG2, TAG3) and adds the TAG name to the GLOBAL signal names that are created.
For_Each /Iteration_Parameter_Name= TAG_NAMES /Items= TAG1+TAG2+TAG3 ; Select_Active_File /File_Name= ::TAG_NAMES ; Metric_Mean /RESULT_METRIC_NAME=_&::TAG_NAMES /APPLY_AS_SUFFIX_TO_SIGNAL_NAME=TRUE ! /RESULT_METRIC_FOLDER=PROCESSED /SIGNAL_TYPES=TARGET ! /SIGNAL_NAMES= ! /SIGNAL_FOLDER=ORIGINAL ! /SIGNAL_COMPONENTS=ALL_COMPONENTS ! /COMPONENT_SEQUENCE= /EVENT_SEQUENCE= /EXCLUDE_EVENTS= ! /GENERATE_MEAN_AND_STDDEV=TRUE ! /APPEND_TO_EXISTING_VALUES=FALSE ; End_For_Each /Iteration_Parameter_Name=TAG_NAMES ;
Example: Use a separate threshold for each event sequence
For example, we want to use the mean GRF signal from each stance phase as a threshold for placing an event within that stance phase.
! Define the event sequence for convenience Event_Define_Event_Sequence /EVENT_SEQUENCE_NAME=STANCE /EVENT_SEQUENCE=RON+ROFF ! /EXCLUDE_EVENTS= ! /INSIDE_OF_SEQUENCE= ! /OFFSET_FROM_START= ! /OFFSET_FROM_END= ! /OFFSET_BY=PERCENT /EVENT_SEQUENCE_INSTANCE=0 ; ! Calculate the mean GRFs as metrics, these will be our thresholds Metric_Mean ! /RESULT_METRIC_FOLDER=PROCESSED /RESULT_METRIC_NAME=THRESHOLD ! /APPLY_AS_SUFFIX_TO_SIGNAL_NAME=FALSE /SIGNAL_TYPES=LINK_MODEL_BASED ! /SIGNAL_FOLDER=ORIGINAL /SIGNAL_NAMES=RGRF /COMPONENT_SEQUENCE=Z /EVENT_SEQUENCE=STANCE /EXCLUDE_EVENTS= /SEQUENCE_PERCENT_START= /SEQUENCE_PERCENT_END= /GENERATE_MEAN_AND_STDDEV=FALSE ! /GENERATE_MEAN_AND_STDDEV_ACROSS_SUBJECTS=FALSE ! /APPEND_TO_EXISTING_VALUES=FALSE ; ! Set the calculated mean GRFs as a pipeline parameter Set_Pipeline_Parameter_From_Expression /PARAMETER_NAME=MEANS_LIST /EXPRESSION=METRIC::PROCESSED::THRESHOLD /AS_INTEGER=FALSE ; ! Iterate over the list of mean GRFs. ! During each loop we can reference the current mean GRF as ::MEAN_GRF ! and we can reference the current loop number as ::COUNT For_Each /ITERATION_PARAMETER_NAME=MEAN_GRF /ITERATION_PARAMETER_COUNT_NAME=COUNT ! /ITERATION_PARAMETER_COUNT_BUFFER= /ITEMS=::MEANS_LIST ; ! Place an event when the GRF signal descends below the mean GRF for that stance phase ! The parameter /EVENT_SEQUENCE_INSTANCE=::COUNT restricts this command to stance phase number ::COUNT Event_Threshold /RESULT_EVENT_NAME=BELOW_THRESHOLD /SIGNAL_TYPES=LINK_MODEL_BASED ! /SIGNAL_FOLDER=ORIGINAL /SIGNAL_NAMES=RGRF /SIGNAL_COMPONENTS=Z ! /FRAME_OFFSET=0 ! /TIME_OFFSET= /EVENT_SEQUENCE=STANCE ! /EXCLUDE_EVENTS= /EVENT_SEQUENCE_INSTANCE=::COUNT ! /EVENT_SUBSEQUENCE= ! /SUBSEQUENCE_EXCLUDE_EVENTS= ! /EVENT_SUBSEQUENCE_INSTANCE=0 /EVENT_INSTANCE=1 /THRESHOLD=::MEAN_GRF /ON_ASCENT=FALSE /ON_DESCENT=TRUE ! /FRAME_WINDOW=8 ! /ENSURE_FRAMES_BEFORE=FALSE ! /ENSURE_FRAMES_AFTER=FALSE ; ! Complete the For_Each loop End_For_Each /ITERATION_PARAMETER_NAME=MEAN_GRF ;
Example: Process many files
First create a pipeline parameter that contains all of the filenames selected (e.g. all files that have the same TAG) concatenated into a string.
Set_Pipeline_Parameter_To_List_Of_Tagged_Files /PARAMETER_NAME=FILENAMES /TAG_NAME= ALL_MALES ! /GET_CURRENT_SELECTED_FILES= false ! /USE_SHORT_FILENAMES= false ; ! Now set up the for each loop using this string For_Each /ITERATION_PARAMETER_NAME= INDEX /ITEMS= ::FILENAMES ; ! Put any command that you like into this location End_For_Each /ITERATION_PARAMETER_NAME= INDEX ;
NOTE: Filenames do not have to be in any sequence or have any special naming convention.
Additional Examples
The Export_Data_to_ASCII_File command's page contains several examples which use For_Each and End_For_Each to export data from individual C3D files to unique text files.
The Get_Pipeline_Parameter_Index_Value command can be used to iterate through a second (or more) list in parallel to the current For_Each command's Items.