Insert Family at Open Connector

Currently stuck. Trying to insert a sprinkler family parallel to an open fitting connector point. The pipe and fitting is at an angle in the Z axis (10 deg), but this could vary. The script work well for pipes that are flat but as soon as they are off parallel then the family is inserted at the wrong angle.
I’ve looked at lots of options but I’m afraid that what I’m looking for is above my level of expertise. Any help that can be provided will be gratefully received.Sprinkler Fitting with Open Connectors.dyn (29.9 KB)