(defun c:refine ();define command to add vertices to the midpoint of each segment of each LWPOLYLINE in a selection set chosen by user (setq ss (ssget (list (cons 0 "LWPOLYLINE"))) i 0);filter out non lwpolylines (which precludes "contigency" in utility routine below) (setq os (getvar "osmode"))(setvar "osmode" 0);store osnap mode and turn off object snaps (while (< i (sslength ss)) (refine-lwpolyline (ssname ss i)) (setq i (1+ i)) ) (setvar "osmode" os);restore object snap settings (princ " added midpoint vertices to ")(princ i)(princ " lwpolylines ") (if (= "Y" (strcase (getstring "\n Erase original lwpolylines?[Y/N]: "))) ;then (command "erase" "previous" "") ;else (princ "\n original polylines are your Previous selection set ") ) (princ) ) (defun refine-lwpolyline (lwpoly);;add vertices to the midpoint of each segment of an LWPOLYLINE (setq coorddata (lwpline-pointlist lwpoly) elevation (car coorddata) coorddata (cdr coorddata) previouspoint (car coorddata) coorddata (cdr coorddata);shave first point off of list newlis (list previouspoint) ;place to store new data index 0 ) (while (< index (length coorddata)) (setq nextpoint (nth index coorddata) midpoint (mapcar '(lambda (a b)(/ (+ a b) 2.0)) previouspoint nextpoint);apply averaging function to adjacent vertices newlis (cons nextpoint (cons midpoint newlis));add midpoint, add original next point previouspoint nextpoint;bump previouspoint ahead to next original vertex index (1+ index);increment index [note that 1+ is actually a function - this is the same as (+ 1 index) but faster] ) ) (setq newlis (reverse newlis));restore original order (setq firstpoint (car newlis) newlis (cdr newlis));first point is extracted: it will be entered with an elevation; rest will not (command "pline" (list (car firstpoint) (cadr firstpoint) elevation));include elevation with first vertex (mapcar 'command newlis);supply the rest of the new vertices without elevation [they inherit elevation from the first point] (command "");exit pline command ) (defun error-report () (princ " error: see Josh") ) ;internal utilities........................................................ (defun dxf (c eg)(cdr (assoc c eg))) ; (defun lwpline-pointlist (e / eg elevation xylis);get coordinates of vertices (setq eg (entget e));obtain entity data (cond ((= "POLYLINE" (dxf 0 eg))(error-report) nil);haven't yet prepared for this contingency as I consider it remote ((/= "LWPOLYLINE" (dxf 0 eg))(princ " error: lwpline-pointlist was fed a non polyline ")) (t (setq elevation (dxf 38 eg) xylis nil);extract the single elevation for all vertices (while (setq eg (member (assoc 10 eg) eg));loop thru data list (setq xylis (cons (cdar eg) xylis) eg (cdr eg));extracting coordinates ) (cons elevation (reverse xylis));return list in proper order with elevation tacked onto front ) ) ) ;(defun c:test-lwpline-pointlist ()(lwpline-pointlist (car (entsel))))