That looks more difficult than you might imagine. A routine would need to figure out how the red rectangles relate to each other, as well as each one relates to both points, to have any hope of finding appropriate locations for drawing a Polyline path.
All sorts of questions arise.... Would there ever be more than 2 red rectangles? Would they ever not be touching each other? Would they ever meet at a T shape rather than an L shape, or both cross each other [an X]? Would the desired result always need to be in orthogonal directions, or might there ever be non-orthogonal angles involved? Would the Start point ever not be in line with the center-line of one of the rectangles, as the end point is not? Would you be willing to restrict selection of the red rectangles to be in the order along which the path should follow them?
You haven't said what the red rectangles are. I expect they're LWPolylines, but they could be [2D] Solids, 3D Solids, Traces, Blocks, 3DPolylines, made up of separate Lines, Mlines with Lines across the ends, or maybe some other things, which would have different criteria for calculating locations. If they represent something like cable trays [whether overhead or under a raised floor], are they at different Z coordinate elevations than the Start and End points? If so, should the path be drawn at their elevation, or at the elevation of the Start and End? Should it be a 3D Polyline path so that it can include vertical legs to get between the cable trays [if that's what they are] and the Start and End?
I don't want to sound discouraging, but I expect that you could just do this manually, with [in the case of your sample image] one Mid-of-2 Object Snap at the bend between red rectangles, and one .X coordinate filter to find where the bend out of one red rectangle toward the End point goes, very quickly without any routine, or with some practice with Object-Snap Tracking [which takes some getting used to, but is pretty powerful]. And you could do a whole lot of them that way in far less time than it would take to come up with a Lisp routine that could account for all possible configurations.
Kent Cooper, AIA