<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Convert 3D Poly to 2D Poly using Average Elevation in Visual LISP, AutoLISP and General Customization Forum</title>
    <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/convert-3d-poly-to-2d-poly-using-average-elevation/m-p/7494630#M112885</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/506682"&gt;@ArchD&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;....... converts a 3D Polyline to a 2D Polyline&amp;nbsp;set to&amp;nbsp;the average elevation ..........&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/506682"&gt;@ArchD&lt;/a&gt;, maybe start with below code. No testing and error trap but I imagine you can add that yourself.&lt;/P&gt;
&lt;PRE&gt;(defun c:somefunc  (/ ent ent2 etdata lst cl)
 (setq ent2 (car (entsel "\nSelect 3D poly:"))
       cl   (cdr (assoc 70 (entget ent2)))
       ent  ent2)
 (while (and (setq ent (entnext ent)) (/= "SEQEND" (cdr (assoc 0 (setq etdata (entget ent))))))
  (setq lst (cons (assoc 10 etdata) lst)))
 (entmake (append (list '(0 . "LWPOLYLINE")
                        '(100 . "AcDbEntity")
                        '(100 . "AcDbPolyline")
                        (cons 38 (/ (apply '+ (mapcar 'cadddr lst)) (length lst))))
                  (list (cons 90 (length lst)) (cons 70 (+ 128 (logand 1 cl))))
                  lst))
 (entdel ent2)
 (princ))
&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="3d_poly_to_lwpoly.gif" style="width: 548px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/418266i9A32FE47C8814FD9/image-size/large?v=v2&amp;amp;px=999" role="button" title="3d_poly_to_lwpoly.gif" alt="3d_poly_to_lwpoly.gif" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 26 Oct 2017 18:54:07 GMT</pubDate>
    <dc:creator>Ranjit_Singh</dc:creator>
    <dc:date>2017-10-26T18:54:07Z</dc:date>
    <item>
      <title>Convert 3D Poly to 2D Poly using Average Elevation</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/convert-3d-poly-to-2d-poly-using-average-elevation/m-p/7494533#M112884</link>
      <description>&lt;P&gt;I'm looking for a lisp that converts a 3D Polyline to a 2D Polyline&amp;nbsp;set to&amp;nbsp;the average elevation of the original 3D Polyline elevations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help finding one would greatly be appreciated.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2017 18:27:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/convert-3d-poly-to-2d-poly-using-average-elevation/m-p/7494533#M112884</guid>
      <dc:creator>ArchD</dc:creator>
      <dc:date>2017-10-26T18:27:11Z</dc:date>
    </item>
    <item>
      <title>Re: Convert 3D Poly to 2D Poly using Average Elevation</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/convert-3d-poly-to-2d-poly-using-average-elevation/m-p/7494630#M112885</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/506682"&gt;@ArchD&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;....... converts a 3D Polyline to a 2D Polyline&amp;nbsp;set to&amp;nbsp;the average elevation ..........&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/506682"&gt;@ArchD&lt;/a&gt;, maybe start with below code. No testing and error trap but I imagine you can add that yourself.&lt;/P&gt;
&lt;PRE&gt;(defun c:somefunc  (/ ent ent2 etdata lst cl)
 (setq ent2 (car (entsel "\nSelect 3D poly:"))
       cl   (cdr (assoc 70 (entget ent2)))
       ent  ent2)
 (while (and (setq ent (entnext ent)) (/= "SEQEND" (cdr (assoc 0 (setq etdata (entget ent))))))
  (setq lst (cons (assoc 10 etdata) lst)))
 (entmake (append (list '(0 . "LWPOLYLINE")
                        '(100 . "AcDbEntity")
                        '(100 . "AcDbPolyline")
                        (cons 38 (/ (apply '+ (mapcar 'cadddr lst)) (length lst))))
                  (list (cons 90 (length lst)) (cons 70 (+ 128 (logand 1 cl))))
                  lst))
 (entdel ent2)
 (princ))
&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="3d_poly_to_lwpoly.gif" style="width: 548px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/418266i9A32FE47C8814FD9/image-size/large?v=v2&amp;amp;px=999" role="button" title="3d_poly_to_lwpoly.gif" alt="3d_poly_to_lwpoly.gif" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2017 18:54:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/convert-3d-poly-to-2d-poly-using-average-elevation/m-p/7494630#M112885</guid>
      <dc:creator>Ranjit_Singh</dc:creator>
      <dc:date>2017-10-26T18:54:07Z</dc:date>
    </item>
    <item>
      <title>Re: Convert 3D Poly to 2D Poly using Average Elevation</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/convert-3d-poly-to-2d-poly-using-average-elevation/m-p/7494664#M112886</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe you can get some inspiration from this quite old one from my tool box.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;;; Flatten a 3d polyline into a lwpolyline
(defun c:FlatPline (/ *error* 3d-coord-&amp;gt;pt-lst doc opt del pts ss alt zlst pl)
  (vl-load-com)
  
  (defun *error* (msg)
    (and (/= msg "Function cancelled")
         (princ (strcat "\nError: " msg))
    )
    (and ss (vla-delete ss))
    (vla-EndUndoMark doc)
    (princ)
  )

;;; 3d-coord-&amp;gt;pt-lst Converts a flat coordinates list into a point list.
;;; (3d-coord-&amp;gt;pt-lst '(1.0 2.0 3.0 4.0 5.0 6.0)) -&amp;gt; ((1.0 2.0 3.0) (4.0 5.0 6.0))

(defun 3d-coord-&amp;gt;pt-lst (lst)
  (if lst
    (cons (list (car lst) (cadr lst) (caddr lst))
          (3d-coord-&amp;gt;pt-lst (cdddr lst))
    )
  )
)
  
  (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (if (ssget '((0 . "POLYLINE") (-4 . "&amp;amp;") (70 . 8)))
    (progn
      (vla-StartUndoMark doc)
      (initget "maXimum miNimum Average")
      (setq opt (cond
                  ((getkword "\Elevation of the polyline plane [maXimum/miNimum/Average] &amp;lt;A&amp;gt;: "))
                  (T "Average")
                )
      )
      (initget "Yes No")
      (setq del (cond
                  ((getkword "\nDelete the 3d polyline source? [Yes/No] &amp;lt;N&amp;gt;: "))
                  (T "No")
                )
      )
      (vlax-for p (setq ss (vla-get-ActiveSelectionSet doc))
        (setq pts (3d-coord-&amp;gt;pt-lst (vlax-get p 'Coordinates))
              zlst (mapcar 'caddr pts)
              alt (cond
                    ((= opt "maXimum")
                     (apply 'max zlst)
                    )
                    ((= opt "miNimum")
                     (apply 'min zlst)
                    )
                    (T (/ (apply '+ zlst) (length pts)))
                  )
              pl  (vlax-invoke
                    (vla-get-ModelSpace doc)
                    'addLightWeightPolyline
                    (apply
                      'append
                      (mapcar
                        '(lambda (p)
                           (setq p (trans p 0 (trans '(0 0 1) 1 0 T)))
                           (list (car p) (cadr p))
                         )
                        pts
                      )
                    )
                  )
        )
        (vla-put-elevation pl alt)
        (vla-put-Closed pl (vla-get-Closed p))
        (if (= del "Yes")
          (vla-delete p)
        )
      )
      (vla-delete ss)
      (vla-EndUndoMark doc)
    )
  )
  (princ)
)&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 Oct 2017 19:08:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/convert-3d-poly-to-2d-poly-using-average-elevation/m-p/7494664#M112886</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2017-10-26T19:08:20Z</dc:date>
    </item>
    <item>
      <title>Re: Convert 3D Poly to 2D Poly using Average Elevation</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/convert-3d-poly-to-2d-poly-using-average-elevation/m-p/7494688#M112887</link>
      <description>&lt;P&gt;Thanks Ranjit, you are&amp;nbsp;appreciated as always.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2017 19:16:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/convert-3d-poly-to-2d-poly-using-average-elevation/m-p/7494688#M112887</guid>
      <dc:creator>ArchD</dc:creator>
      <dc:date>2017-10-26T19:16:18Z</dc:date>
    </item>
    <item>
      <title>Re: Convert 3D Poly to 2D Poly using Average Elevation</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/convert-3d-poly-to-2d-poly-using-average-elevation/m-p/7495493#M112888</link>
      <description>&lt;P&gt;I like it!&lt;/P&gt;
&lt;P&gt;I am just wondering if the OP wants a weighted average based on the length between vertices, or just a simple average of all the Zs.&lt;/P&gt;
&lt;P&gt;A 100 init long 3DPOLY might have only 4 vertices with Zs of 1, 100, 100, and 1, with the first and last segments being only 1 unit long each, wherein the weighted average would be 99+, not 50.5.&lt;/P&gt;
&lt;P&gt;BTW, can you really use vla-delete on a selection set object these days (or any days)?&amp;nbsp; I am pretty sure you can't use vla-delete on a PICKSET, right?&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2017 01:52:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/convert-3d-poly-to-2d-poly-using-average-elevation/m-p/7495493#M112888</guid>
      <dc:creator>john.uhden</dc:creator>
      <dc:date>2017-10-27T01:52:39Z</dc:date>
    </item>
    <item>
      <title>Re: Convert 3D Poly to 2D Poly using Average Elevation</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/convert-3d-poly-to-2d-poly-using-average-elevation/m-p/7496697#M112889</link>
      <description>&lt;P&gt;I never really thought about that but a weighted average like you mentioned would be a more accurate elevation for what I'm doing.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2017 12:55:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/convert-3d-poly-to-2d-poly-using-average-elevation/m-p/7496697#M112889</guid>
      <dc:creator>ArchD</dc:creator>
      <dc:date>2017-10-27T12:55:19Z</dc:date>
    </item>
    <item>
      <title>Re: Convert 3D Poly to 2D Poly using Average Elevation</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/convert-3d-poly-to-2d-poly-using-average-elevation/m-p/7497099#M112890</link>
      <description>&lt;P&gt;Maybe like this. Minimal testing&lt;/P&gt;
&lt;PRE&gt;(defun c:somefunc  (/ ent ent2 etdata lst cl td dis lst2)
 (setq ent2 (car (entsel "\nSelect 3D poly:"))
       cl   (assoc 70 (entget ent2))
       ent  ent2
       td   0)
 (while (and (setq ent (entnext ent)) (/= "SEQEND" (cdr (assoc 0 (setq etdata (entget ent))))))
  (setq lst (cons (assoc 10 etdata) lst)))
 (setq lst2 lst
       lst  (mapcar 'cdr lst))
 (entmake
  (append (list '(0 . "LWPOLYLINE")
                '(100 . "AcDbEntity")
                '(100 . "AcDbPolyline")
                (cons 38
                      (/ (apply '+
                                (mapcar '(lambda (x y)
                                          (* (/ (+ (caddr x) (caddr y)) 2)
                                             (progn (setq td (+ td (setq dis (distance (reverse (cdr (reverse x))) (reverse (cdr (reverse y)))))))
                                                    dis)))
                                        (if (= 1 (logand 1 (cdr cl)))
                                         (setq lst (append lst (list (car lst))))
                                         lst)
                                        (cdr lst)))
                         td)))
          (list (cons 90 (length lst2)) cl)
          lst2))
 (entdel ent2)
 (princ))&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="3d_poly_to_lwpoly_weighted_avg.gif" style="width: 548px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/418642iE5886101769D5474/image-size/large?v=v2&amp;amp;px=999" role="button" title="3d_poly_to_lwpoly_weighted_avg.gif" alt="3d_poly_to_lwpoly_weighted_avg.gif" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2017 15:04:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/convert-3d-poly-to-2d-poly-using-average-elevation/m-p/7497099#M112890</guid>
      <dc:creator>Ranjit_Singh</dc:creator>
      <dc:date>2017-10-27T15:04:29Z</dc:date>
    </item>
    <item>
      <title>Re: Convert 3D Poly to 2D Poly using Average Elevation</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/convert-3d-poly-to-2d-poly-using-average-elevation/m-p/7497100#M112891</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/506682"&gt;@ArchD&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I'm looking for a lisp that converts a 3D Polyline to a 2D Polyline&amp;nbsp;set to&amp;nbsp;the average elevation of the original 3D Polyline elevations.&amp;nbsp; ....&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Here's another kind-of interesting way to do it, using VLA Properties instead of entity data, so it doesn't need to mess with the fact that each vertex of a 3DPolyline is its own entity.&amp;nbsp; Interestingly, you can&amp;nbsp;impose a list of Coordinates&amp;nbsp;on a Polyline object this way &lt;EM&gt;even without the number of vertices matching&lt;/EM&gt;, so&amp;nbsp;this just &lt;FONT color="#ff0000"&gt;draws a little starting Polyline of one segment&lt;/FONT&gt;, and then &lt;FONT color="#339966"&gt;&lt;FONT color="#ff00ff"&gt;imposes the XY-only list of Coordinates&lt;/FONT&gt;&lt;/FONT&gt; from the 3DPoly on that, and the &lt;FONT color="#339966"&gt;average Elevation from the Z coordinates&lt;/FONT&gt;.&amp;nbsp; [It's not a weighted average affected by segment lengths, as discussed in recent posts.]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;(defun C:3DLWAvg &lt;FONT color="#3366ff"&gt;; = &lt;STRONG&gt;3D&lt;/STRONG&gt; polyline to &lt;STRONG&gt;LW&lt;/STRONG&gt; polyline at &lt;STRONG&gt;Av&lt;/STRONG&gt;era&lt;STRONG&gt;g&lt;/STRONG&gt;e elevation
&lt;/FONT&gt;  (/ 3dpoly 3dcoords 3dpobj n XYs Zs lwp)
  (setq
    3dpoly (car (entsel "\n3DPolyline to make Average-elevation LWPolyline from: "))
    3dcoords (vlax-get (setq 3dpobj (vlax-ename-&amp;gt;vla-object 3dpoly)) 'Coordinates)
    n -1
  )&lt;FONT color="#999999"&gt;; setq&lt;/FONT&gt;
  (repeat (/ (length 3dcoords) 3)&lt;FONT color="#3366ff"&gt;; for each vertex's worth of XYZ coordinates,&lt;/FONT&gt;
    (setq
      XYs (append XYs (list (nth (setq n (1+ n)) 3dcoords)))&lt;FONT color="#3366ff"&gt;; X coordinate&lt;/FONT&gt;
      XYs (append XYs (list (nth (setq n (1+ n)) 3dcoords)))&lt;FONT color="#3366ff"&gt;; Y [into same list as X]&lt;/FONT&gt;
      Zs (append Zs (list (nth (setq n (1+ n)) 3dcoords)))&lt;FONT color="#3366ff"&gt;; Z [separate list for Elevation]&lt;/FONT&gt;
    )&lt;FONT color="#999999"&gt;; setq&lt;/FONT&gt;
  )&lt;FONT color="#999999"&gt;; repeat&lt;/FONT&gt;
  &lt;FONT color="#ff0000"&gt;(command "_.pline" (getvar 'viewctr) "@1,0" "")&lt;/FONT&gt;&lt;FONT color="#3366ff"&gt;; temporary quickie basis object&lt;/FONT&gt;
  &lt;FONT color="#ff00ff"&gt;(vlax-put (setq lwp (vlax-ename-&amp;gt;vla-object (entlast))) 'Coordinates XYs)
  &lt;FONT color="#339966"&gt;(vlax-put lwp 'Elevation (/ (apply '+ Zs) (length Zs)))&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#3366ff"&gt;; average elevation&lt;/FONT&gt;
&amp;nbsp; (vla-put-Closed lwp (vla-get-Closed 3dpobj))&lt;BR /&gt;  (princ)
)&lt;FONT color="#999999"&gt;; defun&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Lightly tested, and it could use all the usual other enhancements [though the typical Osnap control is not needed even though there's a (command) function involved], as well as some possible more-particular things like making sure PLINEWID is set to 0 [or setting that within the Pline command] if desired.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;[I started out trying (cons) rather than (append) to build the separated-coordinates lists, which would use less code, but with these kinds of values that&amp;nbsp;results in&amp;nbsp;compounded &lt;EM&gt;dotted-pair &lt;/EM&gt;&amp;nbsp;lists.]&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2017 15:15:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/convert-3d-poly-to-2d-poly-using-average-elevation/m-p/7497100#M112891</guid>
      <dc:creator>Kent1Cooper</dc:creator>
      <dc:date>2017-10-27T15:15:47Z</dc:date>
    </item>
    <item>
      <title>Re: Convert 3D Poly to 2D Poly using Average Elevation</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/convert-3d-poly-to-2d-poly-using-average-elevation/m-p/7497240#M112892</link>
      <description>&lt;P&gt;Ranjit, this is perfect, absolutely fantastic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm not sure what I'd do without this forum because I struggle with coding so my appreciation for all of you guys giving their ideas and versions of code is awesome. Thanks everyone for the quick help. This is going to help me out tremendously.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2017 15:47:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/convert-3d-poly-to-2d-poly-using-average-elevation/m-p/7497240#M112892</guid>
      <dc:creator>ArchD</dc:creator>
      <dc:date>2017-10-27T15:47:11Z</dc:date>
    </item>
    <item>
      <title>Re: Convert 3D Poly to 2D Poly using Average Elevation</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/convert-3d-poly-to-2d-poly-using-average-elevation/m-p/7497916#M112893</link>
      <description>&lt;P&gt;If plist is the list of all 3D points, then I think the weighted average would be calculated as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;(defun weighted_av (plist / i p1 p2 Zav seglen tlen weight @2d)
  (defun @2d (p)(list (car p)(cadr p)))
  (setq i  0 weight 0 tlen 0)
  (repeat (1- (length plist))
    (setq p1 (nth i plist)
             p2 (nth ((setq i (1+ i)) plist)
             Zav (* 0.5 (+ (last p1)(last p2)))
             seglen (distance (@2d p1)(@2d p2))
             tlen (+ tlen seglen)
             weight (+ weight (* seglen Zav))
    )
  )
  (/ weight tlen)
)

;; BTW, I find it easier to get the plist from the polyline object's coordinates:

(setq coords (vlax-get 3dpolyobj 'Coordinates)) ;; which is a flat list.

;; then use this function to group the flat list into a list of (x y z) lists.:

(defun @group (old n / item new)
  (while old
    (while (&amp;lt; (length item) n)
      (setq item (cons (car old) item) old (cdr old))
    )
    (setq new (cons (reverse item) new) item nil)
  )
  (reverse new)
)

(setq plist (@group coords 3))&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 Oct 2017 19:52:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/convert-3d-poly-to-2d-poly-using-average-elevation/m-p/7497916#M112893</guid>
      <dc:creator>john.uhden</dc:creator>
      <dc:date>2017-10-27T19:52:27Z</dc:date>
    </item>
    <item>
      <title>Re: Convert 3D Poly to 2D Poly using Average Elevation</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/convert-3d-poly-to-2d-poly-using-average-elevation/m-p/7497947#M112894</link>
      <description>&lt;P&gt;Oops.&amp;nbsp; Get rid of the red parenthesis...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;(defun weighted_av (plist / i p1 p2 Zav seglen tlen weight @2d)
  (defun @2d (p)(list (car p)(cadr p)))
  (setq i 0 weight 0 tlen 0)
  (repeat (1- (length plist))
    (setq p1 (nth i plist)
             p2 (nth &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;(&lt;/FONT&gt;&lt;/STRONG&gt;(setq i (1+ i)) plist)&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;;; here--------------&lt;STRONG&gt;^&lt;/STRONG&gt;&lt;/FONT&gt;
             Zav (* 0.5 (+ (last p1)(last p2)))
             seglen (distance (@2d p1)(@2d p2))
             tlen (+ tlen seglen)
             weight (+ weight (* seglen Zav))
    )
  )
  (/ weight tlen)
)
&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 Oct 2017 20:00:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/convert-3d-poly-to-2d-poly-using-average-elevation/m-p/7497947#M112894</guid>
      <dc:creator>john.uhden</dc:creator>
      <dc:date>2017-10-27T20:00:04Z</dc:date>
    </item>
    <item>
      <title>Re: Convert 3D Poly to 2D Poly using Average Elevation</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/convert-3d-poly-to-2d-poly-using-average-elevation/m-p/7498130#M112895</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/3930636"&gt;@john.uhden&lt;/a&gt;, I think, and I maybe wrong, this will return the same weighted average for a 3d polyline if it were open or closed? Is that the intent or is this code&amp;nbsp;just for open 3d polylines. In any case it's a good utility function for my library &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2017 21:25:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/convert-3d-poly-to-2d-poly-using-average-elevation/m-p/7498130#M112895</guid>
      <dc:creator>Ranjit_Singh</dc:creator>
      <dc:date>2017-10-27T21:25:17Z</dc:date>
    </item>
    <item>
      <title>Re: Convert 3D Poly to 2D Poly using Average Elevation</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/convert-3d-poly-to-2d-poly-using-average-elevation/m-p/7498207#M112896</link>
      <description>&lt;P&gt;Your observation is very sage.&amp;nbsp; It will work for both open and close polylines, but if closed the plist must repeat the starting vertex at the end of the list, as in (p1 p2 p3 p4 p1).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(setq plist (append plist (list (car plist))))&lt;/P&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;P&gt;(setq plist (reverse (cons (car plist)(reverse plist))))&lt;/P&gt;
&lt;P&gt;but for this use of plist, it doesn't matter whether it's reversed or not, so&lt;/P&gt;
&lt;P&gt;(setq plist (cons (car plist)(reverse plist)))&amp;nbsp; ;; will do.&lt;/P&gt;
&lt;P&gt;and consing is much faster then appending.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2017 22:01:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/convert-3d-poly-to-2d-poly-using-average-elevation/m-p/7498207#M112896</guid>
      <dc:creator>john.uhden</dc:creator>
      <dc:date>2017-10-27T22:01:39Z</dc:date>
    </item>
    <item>
      <title>Re: Convert 3D Poly to 2D Poly using Average Elevation</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/convert-3d-poly-to-2d-poly-using-average-elevation/m-p/7498309#M112897</link>
      <description>&lt;P&gt;My apologies, Ranjit.&amp;nbsp; I didn't notice that you were the author of that response.&amp;nbsp; I am honored to think of your adding the code to your library.&amp;nbsp; I would bet that you are the "best-selling" author in that library.&amp;nbsp; Wait, I get it.&amp;nbsp; You'll say just about anything for a paint brush, but I don't have your address.&amp;nbsp; Okay, how about the name and address of your favorite paint store or hardware?&amp;nbsp; Or just their phone number?&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2017 23:18:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/convert-3d-poly-to-2d-poly-using-average-elevation/m-p/7498309#M112897</guid>
      <dc:creator>john.uhden</dc:creator>
      <dc:date>2017-10-27T23:18:06Z</dc:date>
    </item>
    <item>
      <title>Re: Convert 3D Poly to 2D Poly using Average Elevation</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/convert-3d-poly-to-2d-poly-using-average-elevation/m-p/7498336#M112898</link>
      <description>&lt;P&gt;I am bad at creating utility functions. Well maybe not bad, but I just don't think about future. Most of my code is just severely nested functions (&lt;EM&gt;for instance post 7, cons 38 portion&lt;/EM&gt;) which could be easily made into a utility function. I just lack the patience to do that. On the other hand I see that you are very good at creating utility functions. So I wasn't joking when I said I am adding that to my library.&lt;/P&gt;
&lt;P&gt;My lack of patience was also hurting my paint brushes.&amp;nbsp;Fortunately, I have my father in law helping me out. He has a lot&amp;nbsp; more patience cleaning up those brushes &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2017 23:36:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/convert-3d-poly-to-2d-poly-using-average-elevation/m-p/7498336#M112898</guid>
      <dc:creator>Ranjit_Singh</dc:creator>
      <dc:date>2017-10-27T23:36:20Z</dc:date>
    </item>
    <item>
      <title>Re: Convert 3D Poly to 2D Poly using Average Elevation</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/convert-3d-poly-to-2d-poly-using-average-elevation/m-p/7498412#M112899</link>
      <description>&lt;P&gt;I have just one conclusion...&lt;/P&gt;
&lt;P&gt;If you give up on the painting, you don't need to hurt any brushes.&amp;nbsp; Of course, neither will you have a bed in which to sleep.&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 28 Oct 2017 00:38:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/convert-3d-poly-to-2d-poly-using-average-elevation/m-p/7498412#M112899</guid>
      <dc:creator>john.uhden</dc:creator>
      <dc:date>2017-10-28T00:38:40Z</dc:date>
    </item>
  </channel>
</rss>

