<?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: Join lines by layer in Visual LISP, AutoLISP and General Customization Forum</title>
    <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/join-lines-by-layer/m-p/7052604#M120639</link>
    <description>&lt;P&gt;Well,&amp;nbsp;try this routine joining entities (not just lines) by their layer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;(defun c:JoinByLayer ( / ss ent lay asc lst i)
  
  (if (setq ss (ssget "_:L" '((0 . "LINE,LWPOLYLINE,ARC"))))
    (repeat (setq i (sslength ss))
      (setq ent (ssname ss (setq i (1- i)))
	    lay (cdr (assoc 8 (entget ent)))
	    lst (if (setq asc (assoc lay lst))
		  (subst (cons lay (ssadd ent (cdr asc)))
			 asc
			 lst)
		  (cons (cons lay (ssadd ent)) lst)))))
  (foreach e lst
    (progn
      (initcommandversion)
      (command "_.JOIN" (cdr e) "")))
  (princ)
  )&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 01 May 2017 08:36:39 GMT</pubDate>
    <dc:creator>ВeekeeCZ</dc:creator>
    <dc:date>2017-05-01T08:36:39Z</dc:date>
    <item>
      <title>Join lines by layer</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/join-lines-by-layer/m-p/7051838#M120636</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have this beautiful lisp of joining lines together:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;;; Join Lines  -  Lee Mac
;; Joins collinear lines in a selection, retaining all original properties.

(defun c:joinlines ( / process e i l s x )

    (defun process ( l / x r )
        (if (setq x (car l))
            (progn
                (foreach y (cdr l)
                    (if (vl-every '(lambda ( a ) (apply 'LM:collinear-p (cons a (cdr x)))) (cdr y))
                        (setq x (cons (car x) (LM:furthestapart (append (cdr x) (cdr y)))))
                        (setq r (cons y r))
                    )
                )
                (entmake (append (car x) (mapcar 'cons '(10 11) (cdr x))))
                (process r)
            )
        )
    )
    (if (setq s (ssget "_:L" '((0 . "LINE"))))
        (process
            (repeat (setq i (sslength s))
                (setq e (ssname s (setq i (1- i)))
                      x (entget e)
                      e (entdel e)
                      l (cons (list x (cdr (assoc 10 x)) (cdr (assoc 11 x))) l)
                )
            )
        )
    )
    (princ)
)

;; Furthest Apart  -  Lee Mac
;; Returns the two points furthest apart in a given list

(defun LM:furthestapart ( lst / di1 di2 pt1 rtn )
    (setq di1 0.0)
    (while (setq pt1 (car lst))
        (foreach pt2 (setq lst (cdr lst))
            (if (&amp;lt; di1 (setq di2 (distance pt1 pt2)))
                (setq di1 di2
                      rtn (list pt1 pt2)
                )
            )
        )
    )
    rtn
)

;; Collinear-p  -  Lee Mac
;; Returns T if p1,p2,p3 are collinear

(defun LM:Collinear-p ( p1 p2 p3 )
    (
        (lambda ( a b c )
            (or
                (equal (+ a b) c 1e-8)
                (equal (+ b c) a 1e-8)
                (equal (+ c a) b 1e-8)
            )
        )
        (distance p1 p2) (distance p2 p3) (distance p1 p3)
    )
)

(princ)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;, but the problem is that it changes the layer that they apear.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want by selecting the objects it will join them but in &lt;STRONG&gt;&lt;U&gt;their current layer.&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Eyal&lt;/P&gt;</description>
      <pubDate>Sun, 30 Apr 2017 08:47:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/join-lines-by-layer/m-p/7051838#M120636</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-04-30T08:47:04Z</dc:date>
    </item>
    <item>
      <title>Re: Join lines by layer</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/join-lines-by-layer/m-p/7052069#M120637</link>
      <description>&lt;P&gt;What's wrong with the JOIN command? I like using this command myself.&lt;BR /&gt;&lt;BR /&gt;BTW post some sample dwg of what you receive and you what... because as Lee stated at the beginning of his routine it honors its original properties - which is in my understanding the same as your "their current layer".&lt;/P&gt;</description>
      <pubDate>Sun, 30 Apr 2017 16:35:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/join-lines-by-layer/m-p/7052069#M120637</guid>
      <dc:creator>ВeekeeCZ</dc:creator>
      <dc:date>2017-04-30T16:35:06Z</dc:date>
    </item>
    <item>
      <title>Re: Join lines by layer</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/join-lines-by-layer/m-p/7052369#M120638</link>
      <description>&lt;P&gt;I am thinking that he just needs to include the layer in the ssget filter, so that he is not inadvertently joining cats with dogs. &amp;nbsp;If he were he would have to create a new layer like DAT or COG, or is that DOT or CAG? &amp;nbsp;Sorta like the old Laugh-In joke... if Tuesday Weld married Frederick March 3rd, she'd be Tuesday March 3rd.&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2017 00:52:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/join-lines-by-layer/m-p/7052369#M120638</guid>
      <dc:creator>john.uhden</dc:creator>
      <dc:date>2017-05-01T00:52:52Z</dc:date>
    </item>
    <item>
      <title>Re: Join lines by layer</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/join-lines-by-layer/m-p/7052604#M120639</link>
      <description>&lt;P&gt;Well,&amp;nbsp;try this routine joining entities (not just lines) by their layer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;(defun c:JoinByLayer ( / ss ent lay asc lst i)
  
  (if (setq ss (ssget "_:L" '((0 . "LINE,LWPOLYLINE,ARC"))))
    (repeat (setq i (sslength ss))
      (setq ent (ssname ss (setq i (1- i)))
	    lay (cdr (assoc 8 (entget ent)))
	    lst (if (setq asc (assoc lay lst))
		  (subst (cons lay (ssadd ent (cdr asc)))
			 asc
			 lst)
		  (cons (cons lay (ssadd ent)) lst)))))
  (foreach e lst
    (progn
      (initcommandversion)
      (command "_.JOIN" (cdr e) "")))
  (princ)
  )&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2017 08:36:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/join-lines-by-layer/m-p/7052604#M120639</guid>
      <dc:creator>ВeekeeCZ</dc:creator>
      <dc:date>2017-05-01T08:36:39Z</dc:date>
    </item>
  </channel>
</rss>

