This AutoCAD routine by Alan Thompson will join supported entities on the same layer into polylines. For example, if you pick a single object, all lines, arcs, and polylines on that layer will be joined into one or more polylines. The same theory applies if you pick three objects on three different layers; the process iterates the layers of the selected objects, joining entities as it can. The end result may be one or more polylines.
The routine drives the built-in AutoCAD command PEdit, but without you having to isolate layers. Anything PEdit can join should also work with this routine.
Start by loading the LISP file, then type in the command MJL. Select one or more entities and press Enter. Thanks, Alan.