join points closer to each other

join points closer to each other

diegolopezsilanes
Advocate Advocate
1,322 Views
3 Replies
Message 1 of 4

join points closer to each other

diegolopezsilanes
Advocate
Advocate

Captura.JPGHi, Im trying to join with lines the 2 closer points to another from a selection set , the code is not working, the third point does not correspond to the third point in distance to the initial point. the line ends do not correspond with the second one, which is supposed to be closer. and i dont find the mistakes.
thanks

(defun minusLenth (s ss2)
(repeat (setq i (sslength s))
(setq i (1- i)
n (ssname s i)
d (setq d (distance c (cdr (assoc 10 (entget n)))))
)
; (if l 
; (and (< d l)
(setq l d
o n
)
; )
; (setq l d)
; )
	(if (= p2 nil) 
	(setq p2 (cdr (assoc 10 (entget o))))
	(setq p3 (cdr (assoc 10 (entget o))))
	)
)
(setq ss2 (ssadd o ss2))
)

; 18:32 12/06/2019
; 18:44 16/06/2019
 ; (defun c:Test (/ p s e c i n d l o)
(defun c:86 ()
;; Tharwat - 27.May.19 ;;
(setq ss2 (ssadd) )
; (setq ss2 nil) ;;;;;;;;;;;;;;;;;;;,
(setq s nil)
(setq p nil)
(setq p2 nil
	p3 nil)
(princ "\nSelect point objectSSSS :")
(if 
(and 
(setq s (ssget '((0 . "POINT"))))
(setq p (ssname s 0))
(setq p1 (cdr (assoc 10 (entget p))))
(setq e p
c (cdr (assoc 10 (entget e)))
s2 (ssdel e s)
)
) ;and
(minusLenth s2 ss2)
; (setq ss2 (ssadd o ss2))
)
(setq s3 (ssdel (ssname ss2 0) s2))
(minusLenth s3 ss2)
; (command "_.Pline"  p1 "GR" "0"  p2  p3 P1  "")
(command "linea" p1 "0,0" "")
(command "linea" p1 p2 p3 p1 "")
(sssetfirst ss2 ss2)
(princ)
)
0 Likes
Accepted solutions (1)
1,323 Views
3 Replies
Replies (3)
Message 2 of 4

dlanorh
Advisor
Advisor
Accepted solution

If I understand you correctly, try this

 

(defun c:test ( / ent i_pt ss cnt s_ent e_lst p_lst v_lst)
  (setq ent (car (entsel "\nSelect Start Point : "))
        i_pt (cdr (assoc 10 (entget ent)))
  );end_setq
  (prompt "\nSelects Points : ")
  (setq ss (ssget '((0 . "POINT"))))
  (if (ssmemb ent ss) (ssdel ent ss))
  (repeat (setq cnt (sslength ss))
    (setq s_ent (ssname ss (setq cnt (1- cnt)))
          e_lst (entget s_ent)
          p_lst (cons (list (cdr (assoc 10 e_lst)) (distance (cdr (assoc 10 e_lst)) i_pt)) p_lst)
    );end_setq
  );end_repeat  
  (setq p_lst (vl-sort p_lst '(lambda(x y) (< (cadr x) (cadr y))))
        v_lst (list i_pt (car (car p_lst)) (car (cadr p_lst)) i_pt)
  );end_setq
  (entmake  (append (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") (cons 90 (1+ (length v_lst))))
                      (mapcar '(lambda (x) (cons 10 x)) v_lst)
            );end_append
  );end_entmake
);end_defun

It first asks for the start point, then a selection set of points. If the start point is included in the selection set it is removed. It currently makes a polyline where the start and end points are the same.

I am not one of the robots you're looking for

0 Likes
Message 3 of 4

dlanorh
Advisor
Advisor

If you want "lines"

 

change this

  (entmake  (append (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") (cons 90 (1+ (length v_lst))))
                      (mapcar '(lambda (x) (cons 10 x)) v_lst)
            );end_append
  );end_entmake
);end_defun

To this

 

  (setq n_ent (entmakex (append (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") (cons 90 (1+ (length v_lst))))
                          (mapcar '(lambda (x) (cons 10 x)) v_lst)
                        );end_append
              );end_entmakex
  );end_setq
  (vl-cmdf "explode" n_ent "")
);end_defun

 

I am not one of the robots you're looking for

0 Likes
Message 4 of 4

Sea-Haven
Mentor
Mentor

The solution for me is "Triangulation" which joins 3 points and does all the searching. There are lisp versions.

0 Likes