From 4dfd42748234cac81bb151e0f3006c27f9599001 Mon Sep 17 00:00:00 2001 From: Christophe Bedard Date: Sun, 23 Mar 2025 10:42:54 -0700 Subject: [PATCH] Add tip for concatenating multiple (Python) substitutions Signed-off-by: Christophe Bedard --- .../Launch/Using-Substitutions.rst | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/source/Tutorials/Intermediate/Launch/Using-Substitutions.rst b/source/Tutorials/Intermediate/Launch/Using-Substitutions.rst index dda8ca7664e..281e22a11d4 100644 --- a/source/Tutorials/Intermediate/Launch/Using-Substitutions.rst +++ b/source/Tutorials/Intermediate/Launch/Using-Substitutions.rst @@ -187,6 +187,26 @@ To do this, create following file in the ``launch`` folder of the ``launch_tutor :language: python :lines: 16-20 + .. tip:: + + A list of substitutions or strings gets concatenated into a single string. + This generally applies to anything that supports substitutions. + + For example, with ``PathJoinSubstitution``, if the file name prefix depended on a launch argument named ``file``, a list of substitutions and strings could be used to create the file name: + + .. code-block:: python + + # Make sure to import LaunchConfiguration: + # from launch.substitutions import LaunchConfiguration + + PathJoinSubstitution([ + FindPackageShare('launch_tutorial'), + 'launch', + [LaunchConfiguration('file', default='example_substitutions'), '_launch', '.py'] + ]) + + In this case, by default, the last path component provided to ``PathJoinSubstitution`` would resolve to ``example_substitutions_launch.py`` and would then be joined with the other path components. + The ``launch_arguments`` dictionary with ``turtlesim_ns`` and ``use_provided_red`` arguments is passed to the ``IncludeLaunchDescription`` action. The ``TextSubstitution`` substitution is used to define the ``new_background_r`` argument with the value of the ``background_r`` key in the ``colors`` dictionary.