Automatic beam trimming

Good afternoon. I searched the entire forum, but found no solution to this problem. I am trying to create a dynamo that will automatically perform pruning between intersections in selected families. Please tell me the correct scheme, maybe someone has faced such a task.