You did not say if this routine should work in 2 or 3D, assuming 2D
Assuming your assembly contains: flange A, Flange B and Pipe
Possible solution could be:
1. Get 2 points interactively, first point on the screen is flangeA side, second point is flange B side. (User can play in this way to orientate on which side will wants flange A and on which angle he wants to have this pipespool.)
2. Insert flange A-block on startpoint with calculated angle between the 2 points. ( Insertionpoint of flange on center of face)
3. Insert flange B-block on endpoint with calculated angle between the 2 points. ( Insertionpoint of flange on center of face)
4. Subtract the working length of both flanges from the calculated length between the 2 points. Draw the 2 lines with this length and ½ diam offset from the centerline between the 2 flanges.
5. Make one block of it.
Hope this helps.
Have fun!
Paul