RepCad Posted May 22, 2019 Share Posted May 22, 2019 (edited) Hi all, I need a code to create list from coordinate of each point with nearest text, for example = ((x y BN6) (x y TS5) (x y B1) (x y B2)) x,y is coordinate of each point. Can someone help me?? Thanks in advanced. Point.dwg Edited May 22, 2019 by amir0914 Quote Link to comment Share on other sites More sharing options...
Emmanuel Delay Posted May 23, 2019 Share Posted May 23, 2019 (edited) Command PCTT (print_out can be adapted, for example more decimal precision, I'm not sure what you want with the result) (defun print_out (lst / a) (foreach a lst (princ "\n") (princ a) ) ) ;; Point Closest To Text (defun c:pctt ( / points texts i j pt ind dst d result) (setq points (ssget "_X" (list (cons 0 "POINT")))) (setq texts (ssget "_X" (list (cons 0 "MTEXT,TEXT")))) (setq i 0) (setq result (list)) (repeat (sslength points) (setq j 0) (setq dst nil) ;; this will hold the closest distance. If a new closer distance is found we replace dst by that new value (setq ind nil) (repeat (sslength texts) (setq d (distance (setq pt (cdr (assoc 10 (entget (ssname points i))))) ;; insert point of the point (cdr (assoc 10 (entget (ssname texts j)))) ;; insert point of the text )) (if (or (= dst nil) (< d dst)) (progn (setq dst d) (setq ind j) )) (setq j (+ j 1)) ) (setq result (append result (list (list (nth 0 pt) ;; x value of point (nth 1 pt) ;; y value of point (cdr (assoc 1 (entget (ssname texts ind)))) ;; text ) ))) (setq i (+ i 1)) ) (print_out result) (princ ) ) Edited May 23, 2019 by Emmanuel Delay 1 Quote Link to comment Share on other sites More sharing options...
RepCad Posted May 23, 2019 Author Share Posted May 23, 2019 Hey, Thank you, but I get below error when run it : error: bad argument type: lselsetp nil Quote Link to comment Share on other sites More sharing options...
Emmanuel Delay Posted May 23, 2019 Share Posted May 23, 2019 Weird, I tried it on your dwg attachment, it works on my pc. Did you try it on that dwg? Maybe there's something different with the dwg you really want to use it on 1 Quote Link to comment Share on other sites More sharing options...
RepCad Posted May 23, 2019 Author Share Posted May 23, 2019 (edited) Sorry, I was running it on another file, I again tested it and works well, thanks a lot. Edited March 31, 2020 by amir0914 1 Quote Link to comment Share on other sites More sharing options...
pBe Posted May 24, 2019 Share Posted May 24, 2019 (edited) On 5/23/2019 at 3:45 PM, Emmanuel Delay said: On 5/23/2019 at 3:45 PM, Emmanuel Delay said: Command PCTT ... Suggestions: Quote ... (setq ind nil) (setq pt (cdr (assoc 10 (entget (ssname points i))))) ;; Move this here (repeat (sslength texts) (setq d (distance pt ;; From here (cdr (assoc 10 (entget (ssname texts j)))) )) ... (setq result (cons (list ;; ucs cons instead of append (lisT (nth 0 pt) (nth 1 pt) (cdr (assoc 1 (entget (ssname texts ind)))) ) ) result )) (ssdel (ssname texts ind) texts) ;; to exclude TEXT that is already paired on the next loop (setq i (+ i 1)) ... Edited May 24, 2019 by pBe 2 Quote Link to comment Share on other sites More sharing options...
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.