<?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: Get and Sort Polyline Start and End Coordinates in Visual LISP, AutoLISP and General Customization Forum</title>
    <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/get-and-sort-polyline-start-and-end-coordinates/m-p/11386791#M41615</link>
    <description>&lt;P&gt;Regards&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/9684048"&gt;@codyhornyak&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try this code&lt;/P&gt;&lt;P&gt;Sort the coordinates of lines or polylines, from East to West and from North to South.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;(defun C:Plset (/ ssMessenger i vlaObject points)
  (setq ssMessenger (ssget "_+.:E:S" '((0 . "LINE,LWPOLYLINE")))
        vlaObject   (vlax-ename-&amp;gt;vla-object (ssname ssMessenger 0))
  )
  (if (not (= (vla-get-Objectname vlaObject) "AcDbLine"))
    (progn
      (setq points (vlax-get vlaObject 'coordinates) ; get coordinates
            lf     (pts2 points)
      )
    )
    (progn
      (setq lf (list (vlax-get vlaObject 'startpoint)
                     (vlax-get vlaObject 'endpoint)
               )
      )
    )
  )
  (print (setq lf_e (vl-sort lf '(lambda (e1 e2) (&amp;lt; (car e1) (car e2))))))
                                                  ;Points, sorted by Easting-West coordinate
  (print (setq lf_n (vl-sort lf '(lambda (e1 e2) (&amp;gt; (cadr e1) (cadr e2))))))
                                                  ;Points, sorted by Norting-Sur coordinate
  (princ)
)                                                 ; defun PLINESELSET

(defun pts2 (lp)
  (if lp
    (cons
      (setq lpt (list (nth 0 lp) (nth 1 lp)))
      (pts2 (cddr lp))
    )
  )
)
&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 29 Aug 2022 03:34:54 GMT</pubDate>
    <dc:creator>calderg1000</dc:creator>
    <dc:date>2022-08-29T03:34:54Z</dc:date>
    <item>
      <title>Get and Sort Polyline Start and End Coordinates</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/get-and-sort-polyline-start-and-end-coordinates/m-p/11386284#M41611</link>
      <description>&lt;P&gt;I am working on a LISP to get and sort polyline start and end coordinates. This is what I have so far. Line 7 is giving me issues. How should I change this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;(defun C:PLINESELSET

  (/ ssMessenger i vlaObject points alldata_plines)

  (setq ssMessenger (ssget "x" '(0 . "LINE,*LWPOLYLINE")))
  (repeat (setq i (sslength ssMessenger)) ; repeat for each line found
    (setq vlaObject (vlax-ename-&amp;gt;vla-object (ssname ssMessenger (setq i (1 - i)))))
    (setq points (vlax-get-property vlaObject 'coordinates)) ; get coordinates
    (setq alldata_plines
      (cons
        (list points)))
  ) ; repeat

  (print alldata_plines)
) ; defun PLINESELSET&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One I get the start and end coordinates of a single polyline, they should be sorted from west to east. Then, once there is a list of all the polyline coordinates in the drawing, they should be sorted from north to south. For example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;PLINE 1 from (0,0) to (1,0)
PLINE 2 from (1,1) to (-1,1)

First, sort each coordinate pair from west to east:
PLINE 1: (0,0) to (1,0)
PLINE 2: (-1,1) to (1,1)

Then, sort each coordinate pair from north to south(can just use y-coordinate of the first coordinate in the pair:
PLINE 2: (-1,1) to (1,1)
PLINE 1: (0,0) to (1,0)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hopefully this question makes sense. Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 28 Aug 2022 18:07:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/get-and-sort-polyline-start-and-end-coordinates/m-p/11386284#M41611</guid>
      <dc:creator>codyhornyak</dc:creator>
      <dc:date>2022-08-28T18:07:18Z</dc:date>
    </item>
    <item>
      <title>Re: Get and Sort Polyline Start and End Coordinates</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/get-and-sort-polyline-start-and-end-coordinates/m-p/11386318#M41612</link>
      <description>&lt;P&gt;Here you are. Note that&lt;/P&gt;
&lt;P&gt;* got start and end points&lt;/P&gt;
&lt;P&gt;* made a list of these two&lt;/P&gt;
&lt;P&gt;* sorted lst of them by X&lt;/P&gt;
&lt;P&gt;* added a sorted lst to the overall lst&lt;/P&gt;
&lt;P&gt;* sorted the overall lst by Y.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;(defun c:Plinesort ( / s i e l)

  (if (setq s (ssget '((0 . "LWPOLYLINE,LINE"))))
    (repeat (setq i (sslength s))
      (setq e (ssname s (setq i (1- i)))
	    l (cons (vl-sort (list (vlax-curve-getstartpoint e) (vlax-curve-getendpoint e))
			     '(lambda (e1 e2) (&amp;lt; (car e1) (car e2))))
		    l))))
  
  (vl-sort l '(lambda (e1 e2) (&amp;gt; (cadar e1) (cadar e2))))
  (print l)
  (princ)
  )
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;*LWPOLYLINE does not make sense. it should be *POLYLINE&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To build a list, use (setq l (cons &lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;item&lt;/FONT&gt; &lt;/STRONG&gt;l)). In this case, it should be (setq l (cons &lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;(list startpt endpt)&lt;/STRONG&gt;&lt;/FONT&gt; l).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think I already linked this to you... Need to be familiar with&amp;nbsp;&lt;A href="https://help.autodesk.com/view/ACD/2022/ENU/?guid=GUID-4684C76F-02F7-4989-AA53-C886E528350A" target="_blank" rel="noopener"&gt;THIS&lt;/A&gt;&amp;nbsp; group of CURVE functions.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 28 Aug 2022 19:06:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/get-and-sort-polyline-start-and-end-coordinates/m-p/11386318#M41612</guid>
      <dc:creator>ВeekeeCZ</dc:creator>
      <dc:date>2022-08-28T19:06:53Z</dc:date>
    </item>
    <item>
      <title>Re: Get and Sort Polyline Start and End Coordinates</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/get-and-sort-polyline-start-and-end-coordinates/m-p/11386573#M41613</link>
      <description>&lt;P&gt;Thanks a bunch&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1779365"&gt;@ВeekeeCZ&lt;/a&gt;&amp;nbsp;. I am learning, its just taking time. I have this LISP wrapped up for now, moving onto the next one shortly.&lt;/P&gt;</description>
      <pubDate>Sun, 28 Aug 2022 23:28:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/get-and-sort-polyline-start-and-end-coordinates/m-p/11386573#M41613</guid>
      <dc:creator>codyhornyak</dc:creator>
      <dc:date>2022-08-28T23:28:05Z</dc:date>
    </item>
    <item>
      <title>Re: Get and Sort Polyline Start and End Coordinates</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/get-and-sort-polyline-start-and-end-coordinates/m-p/11386692#M41614</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/9684048"&gt;@codyhornyak&lt;/a&gt;,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Congrats on your efforts and success.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Aug 2022 01:52:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/get-and-sort-polyline-start-and-end-coordinates/m-p/11386692#M41614</guid>
      <dc:creator>JBerns</dc:creator>
      <dc:date>2022-08-29T01:52:58Z</dc:date>
    </item>
    <item>
      <title>Re: Get and Sort Polyline Start and End Coordinates</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/get-and-sort-polyline-start-and-end-coordinates/m-p/11386791#M41615</link>
      <description>&lt;P&gt;Regards&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/9684048"&gt;@codyhornyak&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try this code&lt;/P&gt;&lt;P&gt;Sort the coordinates of lines or polylines, from East to West and from North to South.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;(defun C:Plset (/ ssMessenger i vlaObject points)
  (setq ssMessenger (ssget "_+.:E:S" '((0 . "LINE,LWPOLYLINE")))
        vlaObject   (vlax-ename-&amp;gt;vla-object (ssname ssMessenger 0))
  )
  (if (not (= (vla-get-Objectname vlaObject) "AcDbLine"))
    (progn
      (setq points (vlax-get vlaObject 'coordinates) ; get coordinates
            lf     (pts2 points)
      )
    )
    (progn
      (setq lf (list (vlax-get vlaObject 'startpoint)
                     (vlax-get vlaObject 'endpoint)
               )
      )
    )
  )
  (print (setq lf_e (vl-sort lf '(lambda (e1 e2) (&amp;lt; (car e1) (car e2))))))
                                                  ;Points, sorted by Easting-West coordinate
  (print (setq lf_n (vl-sort lf '(lambda (e1 e2) (&amp;gt; (cadr e1) (cadr e2))))))
                                                  ;Points, sorted by Norting-Sur coordinate
  (princ)
)                                                 ; defun PLINESELSET

(defun pts2 (lp)
  (if lp
    (cons
      (setq lpt (list (nth 0 lp) (nth 1 lp)))
      (pts2 (cddr lp))
    )
  )
)
&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Aug 2022 03:34:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/get-and-sort-polyline-start-and-end-coordinates/m-p/11386791#M41615</guid>
      <dc:creator>calderg1000</dc:creator>
      <dc:date>2022-08-29T03:34:54Z</dc:date>
    </item>
  </channel>
</rss>

