Hi @Bek,
You may use the ApplyRules command and select the upslope part and then the farthest downslope part and all in-between will be selected if they are connected, this will apply rules to all selected Structures and Pipes.
However, and if you have different requirements, I tried doing that using Dynamo and found this link that helped me with the attached dynamo script.
Hope this helps.
SendCommand.dyn (13.2 KB)