Message 1 of 4
Join lines by layer
Not applicable
04-30-2017
01:47 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I have this beautiful lisp of joining lines together:
;; 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 (< 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)
, but the problem is that it changes the layer that they apear.
I want by selecting the objects it will join them but in their current layer.
Thank you
Eyal