Without knowing 3 points, it is impossible to do.
Given the solution I provided above, the user will be required to select ENT1 (the object which will be moved and rotated) and will will be required to select PT1, PT2, and PT3 as described in your original post.
However, once those points are selected, it should be possible to get the solution you desire, but there will have to be lots of error checking and conditional operators.
Now, there is a chance it can be done entirely programmtically, but a few criteria would have to be true. First, you would have to select ENT1 and ENT2, then, you would have to obtain a 3d centroid of the solids. After getting the centroids, you would need to programmatically determine the orientation of ENT1. It shouldn't be terribly difficult though considering you already know much about the object, finally, you would use the orientation to generate pt3 programmatically, it isn't necessary to be precise, it merely has to be on a straight line representing the center of the side outlet.
Once you have those points, you can proceed to move ENT1 and rotate it as needed.
I built an example function that will move ENT1 to the correct orientation, but it doesn't work in all cases ... for example, if the angle of ENT2 doesn't intersect with the parallel plane of ENT1, the outlets will never align and you must adjust the rotation angle of ENT2 to match. To see the function in action, merely move ENT1 in either direction in the XY plane.
This can all be done programmatically if you have a set of known points that generate an alignment plane ... geometry 101
(defun C:ObjAlign ()
(prompt "\nSelect target object: ")
(setq ent1 (car (entsel)))
(setq pt2 (getpoint "\nSelect center of base object: " )
pt1 (getpoint "\nSelect center of target object: ")
pt3 (getpoint "\nSelect alignment point on target object: ")
)
;;calculate the rotation angle relative to pt1 and pt3
;;and get the maximum distance between pt1 and pt2
;;strip Z data from points so we get the world plane intersection
(setq pt1a (list (car pt1) (cadr pt1))
pt2a (list (car pt2) (cadr pt2))
pt3a (list (car pt3) (cadr pt3))
)
(setq ang (angle pt3a pt1a)
;;the effective angle of ENT1 parallel to XY plane
ang2 (angtof "90" 4)
;;the offset to make perp line
dist (distance pt2 pt1)
;;maximum distance between ENT1 and ENT2 (in XYZ plane)
)
;;find the intersecting point between a line perpendicular to
;;segment pt3/pt1 and a line parallel to pt3/pt1 originating at pt2
(setq pt4 (inters
pt2a
(polar pt2a ang dist)
(polar pt1 (+ ang ang2) dist)
(polar pt1 (- ang ang2) dist)
)
)
;;the new location of pt1
(setq newpt1 (list (car pt4) (cadr pt4) (caddr pt1)))
;;use the set of points from the previous example
;;returns a point on segment newpt1/pt2
(setq intpt (polar newpt1 (angle newpt1 pt2) (distance pt1 pt3)))
(princ intpt)
(setq newpt3 (inters (list (car intpt)(cadr intpt) -1000)
(list (car intpt)(cadr intpt) 1000)
newpt1
pt2
)
)
;;current rotation angle
(setq chyp (distance pt1 pt3)
cadj (distance (list (car pt1)(cadr pt1))
(list (car pt3)(cadr pt3))
)
)
(setq curang (rtd (acos (/ cadj chyp))))
;;target rotation angle
(setq hyp (distance newpt1 newpt3)
adj (distance (list (car newpt1) (cadr newpt1))
(list (car newpt3) (cadr newpt3))
)
)
(setq tarang (rtd (acos (/ adj hyp))))
(setq newang (- curang tarang))
;;move ENT1
(vl-cmdf "_.move" ENT1 "" pt1 newpt1)
;;rotate ENT1
(vl-cmdf "_.rotate3d"
ENT1
""
"2"
pt1
newpt1
newang
)
)
;;;function for angle calculation
(defun acos (x)
(atan (/ (sqrt (- 1 (* x x))) x))
)
;;;Radians to Degrees
(defun rtd (a)
(/ (* a 180.0) pi)
)