User Tools

Site Tools


visual3d:documentation:pipeline:pipeline_commands:for_each_and_end_for_each

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
visual3d:documentation:pipeline:pipeline_commands:for_each_and_end_for_each [2024/07/16 16:59] – removed sgrangervisual3d:documentation:pipeline:pipeline_commands:for_each_and_end_for_each [2024/09/03 13:57] (current) – [Command Syntax] wikisysop
Line 1: Line 1:
 +====== For Each and End For Each ======
 +
 +Executes pipeline commands multiple times for each item in a list of items. It 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 consequences because it means that you can "loop" through disconnected items or strings as easily as using a structured list.
 +
 +==== Command Syntax ====
 +
 +<code>
 +For_Each
 +/Iteration_Parameter_Name= INDEX
 +!/ITERATION_PARAMETER_COUNT_NAME=
 +/Items= ITEM1+ITEM2+ITEM3
 +;
 +
 +! Starting from the For_Each command and ending at the End_For_Each command
 +! the loop is repeated once for each item in the For_Each command at each
 +! loop INDEX is a pipeline command this is identified as ::INDEX in any other command
 +
 +End_For_Each
 +/Iteration_Parameter_Name=INDEX
 +;
 +</code>
 +
 +As of version 5.02.17, a new parameter "ITERATION_PARAMETER_COUNT_NAME" count was added. A pipeline parameter name (ex. INDEX_COUNT) can be placed here. Any where the parameter INDEX_COUNT is referenced, will return the iteration number (the result will be 1 based, so the first loop through will return 1, and the second will return 2).
 +
 +==== 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.
 +
 +<code>
 +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
 +;
 +</code>
 +
 +==== Example: Implementing a while loop ====
 +
 +Visual3D doesn't have a WHILE command, so there is no option but to use a kludge. You will need to set the option to make Visual3D stop processing the pipeline on the first error. The Visual 3D solution for the following algorithm can be found on [[|Example: Implementing a //while// loop]].
 +
 +<code>
 +Variable blnContinue = true
 +While Continue = true
 +Prompt user for variable blnContinue (true or false)
 +FileCounter = FileCounter +1
 +[load and process another file (e.g. filename_filecounter)]
 +End while
 +</code>
 +==== Example: Processing 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.
 +
 +<code>
 +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
 +;
 +</code>
 +
 +! **NOTE:** Filenames do not have to be in any sequence or have any special naming convention.
 +
 +==== Exporting multiple files ====
 +
 +Using [[#Export_Data_to_ASCII_File|Export_Data_to_ASCII_File]] to export data from individual C3D files to unique text files.
 +
 +[[Visual3D:Documentation:Pipeline:File_Commands:Export_Data_To_ASCII_File#Example_1:_File_Export_of_multiple_files|Export_Data_To_ASCII_File#Example_1:_File_Export_of_multiple_files]]
 +
 +[[Visual3D:Documentation:Pipeline:File_Commands:Export_Data_To_ASCII_File#Example_2:_File_Export_of_multiple_files|Export_Data_To_ASCII_File#Example_2:_File_Export_of_multiple_files]]
 +
 +
  
visual3d/documentation/pipeline/pipeline_commands/for_each_and_end_for_each.1721149193.txt.gz · Last modified: 2024/07/16 16:59 by sgranger