baris gunes Posted February 16 Posted February 16 Hello, I want to find and select the two closest points among the multiple points I will select. It will be much appreciated if you give me some hints, thank you in advance. Quote
robierzo Posted February 17 Posted February 17 Draw a line between the two closest points. (defun c:ordpt(/ lista_puntos list_ord) (setq lista_puntos nil list_ord nil) (setq conj_pt (ssget "_X" '((0 . "POINT")))) (setq n 0) (repeat (sslength conj_pt) (setq lista_puntos (cons (cdr (assoc 10 (entget (ssname conj_pt n)))) lista_puntos)) (setq n (1+ n)) ) (while (setq pt_ini (getpoint"\nSelecciona un punto: ")) (setq list_ord (vl-sort lista_puntos '(lambda (el1 el2) (< (distance pt_ini el1)(distance pt_ini el2)))) ) (entmake (list '(0 . "LINE") '(100 . "AcDbEntity") '(100 . "AcDbLine") (cons 10 (car list_ord)) (cons 11 (cadr list_ord)) ) ) ) (princ) ) 1 Quote
devitg Posted February 17 Posted February 17 (edited) On 2/16/2024 at 10:57 AM, baris gunes said: Hello, I want to find and select the two closest points among the multiple points I will select. It will be much appreciated if you give me some hints, thank you in advance. Edited February 17 by devitg not need to upload Quote
baris gunes Posted February 18 Author Posted February 18 Hello robierzo Many thanks for that, works.. But what I need is to select the points collectively from the screen rather than one by one. Then finding the two points closest to each other among these points.. Baris work_01.dwg Quote
marko_ribar Posted February 18 Posted February 18 https://www.theswamp.org/index.php?topic=40592.msg617865#msg617865 Quote
robierzo Posted February 19 Posted February 19 (edited) You can also try this: (defun c:ordpt (/ lista_puntos list_ord lista_total_dist conj_pt lista_puntos-1 el el1 coord_el d1 lista_dist pt1 pt2) (setq lista_puntos nil list_ord nil lista_total_dist nil) (prompt "\nSelecciona los puntos: ") (setq conj_pt (ssget '((0 . "POINT")))) (setq n 0) (repeat (sslength conj_pt) (setq lista_puntos (cons (ssname conj_pt n) lista_puntos));lista con los nombres de los puntos (setq n (1+ n)) ) (setq lista_puntos-1 (cdr lista_puntos)) (setq n 0) (repeat (1- (length lista_puntos)) (setq el (nth n lista_puntos)) (setq coord_el (cdr (assoc 10 (entget el)))) (foreach el1 lista_puntos-1 (setq coord_el1 (cdr (assoc 10 (entget el1)))) (setq d1 (distance coord_el coord_el1)) (setq lista_dist (list d1 el el1)) (setq lista_total_dist (cons lista_dist lista_total_dist)) ) (setq lista_puntos-1 (cdr lista_puntos-1)) (setq n (1+ n)) ) ;ordenamos de menor a mayor distancia (setq lista_ord (vl-sort lista_total_dist '(lambda (el1 el2) (< (car el1) (car el2))))) ;puntos más cercanos (setq pt1 (cdr (assoc 10 (entget (cadar lista_ord))))) (setq pt2 (cdr (assoc 10 (entget (caddar lista_ord))))) (entmake (list '(0 . "LINE") '(100 . "AcDbEntity") '(100 . "AcDbLine") (cons 10 pt1) (cons 11 pt2) ) ) (princ) ) Edited February 19 by robierzo Quote
fuccaro Posted February 19 Posted February 19 My solution: (defun c:pp() (setq ss (ssget '((0 . "POINT"))) points (sslength ss) ps nil) (repeat (setq i (sslength ss)) (setq ps (cons (cdr (assoc 10 (entget (ssname ss (setq i (1- i)))))) ps))) (setq dl nil) (setq i -1) (repeat (1- points) (setq i (1+ i) j i p1 (nth i ps)) (repeat (- points i 1) (setq j (1+ j) p2 (nth j ps) dist (distance p1 p2)) (setq dl (cons (list dist p1 p2) dl)) ) ) (setq mindist (apply 'min (mapcar 'car dl))) (foreach x dl (if (= mindist (car x)) (entmake (list '(0 . "LINE") '(62 . 3) (cons 10 (cadr x)) (cons 11 (caddr x))))) ) (strcat "Shortest distance= " (rtos mindist)) ) This will output in the command line the shortest distance. Also it will connect with a green line the point pairs placed at exactly that distance from each other. Quote
baris gunes Posted February 23 Author Posted February 23 On 2/19/2024 at 12:40 PM, robierzo said: You can also try this: (defun c:ordpt (/ lista_puntos list_ord lista_total_dist conj_pt lista_puntos-1 el el1 coord_el d1 lista_dist pt1 pt2) (setq lista_puntos nil list_ord nil lista_total_dist nil) (prompt "\nSelecciona los puntos: ") (setq conj_pt (ssget '((0 . "POINT")))) (setq n 0) (repeat (sslength conj_pt) (setq lista_puntos (cons (ssname conj_pt n) lista_puntos));lista con los nombres de los puntos (setq n (1+ n)) ) (setq lista_puntos-1 (cdr lista_puntos)) (setq n 0) (repeat (1- (length lista_puntos)) (setq el (nth n lista_puntos)) (setq coord_el (cdr (assoc 10 (entget el)))) (foreach el1 lista_puntos-1 (setq coord_el1 (cdr (assoc 10 (entget el1)))) (setq d1 (distance coord_el coord_el1)) (setq lista_dist (list d1 el el1)) (setq lista_total_dist (cons lista_dist lista_total_dist)) ) (setq lista_puntos-1 (cdr lista_puntos-1)) (setq n (1+ n)) ) ;ordenamos de menor a mayor distancia (setq lista_ord (vl-sort lista_total_dist '(lambda (el1 el2) (< (car el1) (car el2))))) ;puntos más cercanos (setq pt1 (cdr (assoc 10 (entget (cadar lista_ord))))) (setq pt2 (cdr (assoc 10 (entget (caddar lista_ord))))) (entmake (list '(0 . "LINE") '(100 . "AcDbEntity") '(100 . "AcDbLine") (cons 10 pt1) (cons 11 pt2) ) ) (princ) ) Hello, Fuccaro Thank you for the work, the lisp is successful and works as I want. Many thanks Quote
baris gunes Posted February 23 Author Posted February 23 On 2/19/2024 at 12:40 PM, robierzo said: You can also try this: (defun c:ordpt (/ lista_puntos list_ord lista_total_dist conj_pt lista_puntos-1 el el1 coord_el d1 lista_dist pt1 pt2) (setq lista_puntos nil list_ord nil lista_total_dist nil) (prompt "\nSelecciona los puntos: ") (setq conj_pt (ssget '((0 . "POINT")))) (setq n 0) (repeat (sslength conj_pt) (setq lista_puntos (cons (ssname conj_pt n) lista_puntos));lista con los nombres de los puntos (setq n (1+ n)) ) (setq lista_puntos-1 (cdr lista_puntos)) (setq n 0) (repeat (1- (length lista_puntos)) (setq el (nth n lista_puntos)) (setq coord_el (cdr (assoc 10 (entget el)))) (foreach el1 lista_puntos-1 (setq coord_el1 (cdr (assoc 10 (entget el1)))) (setq d1 (distance coord_el coord_el1)) (setq lista_dist (list d1 el el1)) (setq lista_total_dist (cons lista_dist lista_total_dist)) ) (setq lista_puntos-1 (cdr lista_puntos-1)) (setq n (1+ n)) ) ;ordenamos de menor a mayor distancia (setq lista_ord (vl-sort lista_total_dist '(lambda (el1 el2) (< (car el1) (car el2))))) ;puntos más cercanos (setq pt1 (cdr (assoc 10 (entget (cadar lista_ord))))) (setq pt2 (cdr (assoc 10 (entget (caddar lista_ord))))) (entmake (list '(0 . "LINE") '(100 . "AcDbEntity") '(100 . "AcDbLine") (cons 10 pt1) (cons 11 pt2) ) ) (princ) ) Hello, Robierzoo Thank you for the work, the lisp is successful and works as I want. Many thanks Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.