To reconnect a disconnected valve to a pipe

Hello,

The python code in this post might be of use to you: Invalid Duct/Pipe Connections - #10 by T_Pover