Hi Marko, this is my attempt (not exactly what you want):
(defun test ( elst / nLst RtnLst Lst s1 e1 s2 e2 flg )
(setq nLst (list))
(setq RtnLst (list))
(setq Lst ; assoc list, where every item is (<handle> <StartPt> <EndPt>)
(mapcar (function (lambda (x) (mapcar 'cdr (mapcar 'assoc (list 5 10 11) (list x x x))))) elst)
); setq Lst
(foreach a Lst ; compare every line with every line, using double (foreach)
(foreach b Lst
(and (not (equal (car a) (car b))) ; handles are not equal, continue
(setq
s1 (cadr a) ; first line startpt
e1 (caddr a) ; first line endpt
s2 (cadr b) ; second line startpt
e2 (caddr b) ; second line endpt
); setq
(cond ; flag: 0 - lines don't share points;;; 1 - lines share one of their points;;; 2 - lines are ontop of each other (share both of their points)
(
(not ; lines don't share points
(or
(equal s1 s2 1e-8)
(equal e1 e2 1e-8)
(equal s1 e2 1e-8)
(equal e1 s2 1e-8)
); or
); not
(setq flg 0)
)
(
(or ; lines share one of their points
(equal s1 s2 1e-8)
(equal e1 e2 1e-8)
(equal s1 e2 1e-8)
(equal e1 s2 1e-8)
); or
(setq flg 1)
)
(
(or ; lines are ontop of each other (share both of their points)
(and
(equal s1 s2 1e-8)
(equal e1 e2 1e-8)
)
(and
(equal s1 e2 1e-8)
(equal e1 s2 1e-8)
)
); or
(setq flg 2)
)
); cond
(setq nLst (append (list (list a flg) (list b flg)) nLst)) ; collect list where every item is: (<handle> <StartPt> <EndPt> <flag>)
); and
); foreach
); foreach
(mapcar (function (lambda (x) (cond ((not (member (car x) RtnLst)) (setq RtnLst (cons (car x) RtnLst)))))) ; remove the duplicate handles from the "nLst"
(mapcar (function (lambda (x) (nth x nLst))) (vl-sort-i (mapcar 'cadr nLst) '>)) ; sort the list by the <flag> value
)
RtnLst
); defun
Included some comments to understand easier whats happening.
Assuming you would use it like this:
(if (setq SS (ssget (list (cons 0 "LINE"))))
(repeat (setq i (sslength SS))
(setq elst (cons (entget (ssname SS (setq i (1- i)))) elst))
)
)
(mapcar 'handent (mapcar 'car (test elst)))
HTH