According to your sample drawing here is my early working code.
You have to sequentially to pick points inside closed areas between polyllines you have (red ones) . Code creates bounding polyline and, sorts its points from lower left corner in CCW direction, and craters list pf its segments.
Segments are added to list of all segments. If segment or reverse direction segment is already in the list it is not included. To simplify the code you have to pick sequentially closed areas.
Before you start use command Breakselected from included file breackobjects.lsp to break all polylines to sub-segments defined by touching polylines.
At the end segments stored in variable allsegs have to be written to exit file in desired format (to do).
(defun c:trace_lines_to_file ( / *error*)
(defun *error* ( msg )
(if (not (member msg '("Function cancelled" "quit / exit abort")))
(princ)
)
(setvar 'cmdecho 1)
(command "_.ucs" "w")
(princ)
)
(defun take (amount lst / ret)(repeat amount (setq ret (cons (car lst) (take (1- amount) (cdr lst))))))
(defun take2 (lst) (take 2 lst))
(defun pointlist2d (lst / ret) (while lst (setq ret (cons (take 2 lst) ret) lst (cddr lst))) (reverse ret)) (defun mappend (fn lst)(apply 'append (mapcar fn lst)))
(setvar 'cmdecho 0)
(setq osnap_mode (getvar "osmode"))
(setq to_delete (ssadd) allsegs (list))
(while
(and(setq pt (getpoint "\nPick point inside closed area >")))
(command "_.bpoly" pt "" )
(setq to_delete (ssadd (entlast)to_delete))
(setq eo (vlax-ename->vla-object (entlast)))
(vla-GetBoundingBox eo 'MinP 'MaxP)
(setq pts (pointlist2d (vlax-get eo 'Coordinates)))
(setq xc (/ (apply '+ (mapcar 'car pts)) (length pts)))
(setq yc (/ (apply '+ (mapcar 'cadr pts)) (length pts)))
(setq pc (list xc yc))
(command "_.ucs" pc (vlax-safearray->list minp) "")
(setq pts (vl-sort pts '(lambda (x y) (< (angle (trans pc 0 1) (trans x 0 1))(angle (trans pc 0 1) (trans y 0 1))))))
(setq pts (append pts (list (car pts))))
(command "_.ucs" "w")
(setq segs (list) i -1)
(while (< (setq i (1+ i)) (-(length pts)2))
(setq segs (append segs (list(list (nth i pts)(nth (1+ i) pts)))))
)
(foreach seg segs
(if
(not
(or
(member seg allsegs)
(member (reverse seg) allsegs)
)
)
(setq allsegs (append allsegs (list seg)))
)
)
)
(foreach seg allsegs (princ seg))
(command "_erase" to_delete "" )
(command "_.ucs" "w")
(setvar 'cmdecho 1)
(princ)
)
Miljenko Hatlak

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.