Rotate Family By Vector

Hello Everyone,

I am trying to place hanger on diagonal pipe with proper rotation. I uploaded my script here, it works on some pipe but for not for other. anyone has idea what is my problem?

pipe rotation2.dyn (73.0 KB)