How about a different approach? Jut trace around the Lines, starting from any one of them, adding the far end of each subsequent Line found in relation to the previous one, in a 3DPOLY command, until you get back to the beginning:
(defun C:L23DP ; Lines {to} 3DPolyline
(/ lineA line1 p1 p2 p3 ss)
(setq
lineA (car (entsel "\nSelect one of the Lines to join into a 3D Polyline: ")); starting Line
line1 lineA; working first Line
); setq
(command "_.3DPOLY" ; start 3DPoly command
(setq p1 (cdr (assoc 10 (entget line1)))); working first Line's start
(setq p2 (cdr (assoc 11 (entget line1)))); working first Line's end
); leave in 3DPoly command
(while
(and
(setq
p3 p2 ; previous point for reference
ss (ssget "_F" (list p2 p1) '((0 . "LINE"))); incl. working Line & Lines meeting both ends
line1 (ssname ss 0); first in selection [meets p2 end of working Line]
); setq
(not (equal line1 lineA)); not back to beginning yet
); and
(setq
p1 (cdr (assoc 10 (entget line1)))
p2 ; far end from previous Line
(if (equal p1 p3 1e-6) ; is this the next Line's start?
(cdr (assoc 11 (entget line1))); then -- use its end
p1 ; else -- use its start
); if
p3 p2
); setq
(command p2); feed to 3DPoly command
); while
(command "_undo" "_close"); back off latest and Close [end 3DPOLY]
(prin1)
); defun
Comments:
You don't select all the Lines -- just one of them.
No (vl....) or (function) functions.
It doesn't matter what the drawn order of the Lines was, nor in which direction each was drawn. *
It counts on the set of Lines being closed as you have said they always will be.
It works in the WCS, but could probably be enhanced to work in a non-World UCS.
It draws the 3DPolyline on the current Layer with all current property settings.
If you have running Osnap on, as long as ENDpoint is among the modes, it will work without the need to turn them off. If you might have [for example] MIDpoint but not also ENDpoint or INTersection or NEArest, it will be misled.
It finds three Lines based on a Fence using the "current" one's endpoints, and the setting of line1 [at line 16] seems to be reliable -- the Line off the starting end of the Fence always seems to be the first in the resulting selection -- but I'm not positive that it will always be. [Some other possible selection approaches could get incorrect results depending on the Pickbox size and/or Zoom level, but this seems unaffected by those.]
In trials in your sample drawing, it sometimes ran into a problem down near the bottom -- some kind of backtracking on itself, always at the same location -- but it didn't always do it, and I haven't been able to figure out what could be causing it [e.g. I couldn't find my suspicions of a non-meeting of Line ends, or an overlap, in the area].
It could easily be enhanced to remove the original Lines.
[And it could use some of the regular enhancements -- command echo suppression, Osnap and blip controls, Layer and other property settings, etc.]
* EDIT: In further testing, I'm sometimes running into more of those hold-ups, which may be related to drawn direction. I'll keep trying to figure out what's going on.
Kent Cooper, AIA