If lines can use Join command 1st for this request simpler for user to do join 1st and only write code for plines. Edit for desired layer name.
(defun test (/ pt1 pt2 pt3 pt4 d1 d2 ss x1 y1 x2 y2 oldsnap oldlay)
(setq oldsnap (getvar 'osmode))
(setq oldlay (getvar 'clayer))
;(setvar 'clayer your layername) change to your layer name
(setq lay (cdr (assoc 8 (entget (car (entsel "pick a pline"))))))
(setq ss (ssget (list (cons 0 "lwpolyline") (cons 8 lay))))
(setvar 'osmode 0)
(repeat (setq x (sslength ss))
(setq co-ord '())
(setq plent (ssname ss (setq x (1- x))))
(setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget plent))))
(if (= (length co-ord) 4)
(progn
(setq pt1 (nth 0 co-ord))
(setq pt2 (nth 1 co-ord))
(setq pt3 (nth 2 co-ord))
(setq pt4 (nth 3 co-ord))
(setq d1 (distance pt1 pt2))
(setq d2 (distance pt2 pt3))
(If (< d1 d2)
(progn
(setq x1 (/ (+ (car pt1) (car pt2)) 2.0))
(setq y1 (/ (+ (cadr pt1) (cadr pt2)) 2.0))
(setq x2 (/ (+ (car pt3) (car pt4)) 2.0))
(setq y2 (/ (+ (cadr pt3) (cadr pt4)) 2.0))
(command "line" (list x1 y1) (list x2 y2) "")
)
(progn
(setq x1 (/ (+ (car pt2) (car pt3)) 2.0))
(setq y1 (/ (+ (cadr pt2) (cadr pt3)) 2.0))
(setq x2 (/ (+ (car pt1) (car pt4)) 2.0))
(setq y2 (/ (+ (cadr pt1) (cadr pt4)) 2.0))
(command "line" (list x1 y1) (list x2 y2) "")
)
)
)
(alert " Object has less or more than 4 sides\n \n So skipped")
)
)
(setvar 'osmode oldsnap)
(setvar 'clayer oldlay)
(princ)
)
(test)