ekko Posted July 28, 2021 Posted July 28, 2021 When I select a certain text, I automatically get the text closest to its position? Quote
Tharwat Posted July 28, 2021 Posted July 28, 2021 You can write your routine as follows: 1- Select main text object. 2- Select all texts by function ssget "_X" or better to ask the user to select all around texts to shorten the iteration process. 3- Iterate through the selection set and retrieve the insertion point of texts along with the entity_name and assign them to a list. 4- Sort the list based on shortest distance between the firstly selected text and ones in the list. 5- Finally highlight the first element that is in the sorted list since it is the closest one to text. Turn the bulb up then you will find it somehow easy to do if you have basics of lisp programming at least. Quote
ekko Posted July 28, 2021 Author Posted July 28, 2021 Yes, I am new to lisp. According to the ideas you provided, I think the fourth point is about sorting, which is currently difficult for me to do. Thank you, sir Quote
ekko Posted July 28, 2021 Author Posted July 28, 2021 (edited) 4 hours ago, Tharwat said: You can write your routine as follows: 1- Select main text object. 2- Select all texts by function ssget "_X" or better to ask the user to select all around texts to shorten the iteration process. 3- Iterate through the selection set and retrieve the insertion point of texts along with the entity_name and assign them to a list. 4- Sort the list based on shortest distance between the firstly selected text and ones in the list. 5- Finally highlight the first element that is in the sorted list since it is the closest one to text. Turn the bulb up then you will find it somehow easy to do if you have basics of lisp programming at least. I cannot Iterate through the selection set, and sort. So I assume a point, is to expand the x and y coordinates of the text to define the reference point. It succeeded, but this is not the effect I want. You can help my brother。 When I click, what I get is that the most recent text is the above one. But I need to get the number to the right of × (defun c:tt () (while (not (setq bztc (entsel "\nSelect text:")))) (setq bztc1 (cdr (assoc 8 (entget (car bztc))))) (setq bzwzys (cdr (assoc 7 (entget (car bztc))))) (setq pt (cdr (assoc 10 (entget (car bztc)))) dis3(mapcar '+ pt(list 100 100 0)) dis1 (distance dis3 pt) ) (setq ssff (ssget "_X" (list '(1 . "*#*") (cons 8 bztc1) (cons 7 bzwzys)) ) ) (repeat (setq i (sslength ssff)) (setq es (ssname ssff (setq i (1- i))) edt (entget es) ) (setq pt1 (cdr (assoc 10 edt)) dis2 (distance dis3 pt1) ) (if (< dis2 dis1) (setq k1 es) ) (setq es (ssadd) es (ssadd k1 es)) (sssetfirst nil es) ) (princ) ) Edited July 28, 2021 by ekko Quote
Tharwat Posted July 28, 2021 Posted July 28, 2021 Here is my approach to get the second text that is close to the main selected text. (defun c:Test (/ ssn int sel ent ins lst) ;; Tharwat - 28.Juk.2021 ;; (and (princ "\nSelect Main Text : ") (or (setq sel (ssget "_+.:S" '((0 . "*TEXT")))) (alert "Nothing selected on invalid object. Try again") ) (setq ssn (ssname sel 0) ins (Text:Pt_ (entget ssn)) ) (setq int -1 sel (ssget "_X" '((0 . "*TEXT"))) ) (progn (while (setq int (1+ int) ent (ssname sel int) ) (or (equal ssn ent) (setq lst (cons (list (Text:Pt_ (entget ent)) ent) lst) ) ) ) lst ) (sssetfirst nil (ssadd (cadr (cadr (vl-sort lst '(lambda (j k) (< (distance ins (car j)) (distance ins (car k))) ) ) ) ) ) ) ) (princ) ) (vl-load-com) (defun Text:Pt_ (get_) (cdr (assoc (if (or (eq "MTEXT" (cdr (assoc 0 get_))) (and (zerop (cdr (assoc 72 get_))) (zerop (cdr (assoc 73 get_))) ) ) 10 11 ) get_ ) ) ) 1 Quote
ekko Posted July 29, 2021 Author Posted July 29, 2021 13 hours ago, Tharwat said: Here is my approach to get the second text that is close to the main selected text. (defun c:Test (/ ssn int sel ent ins lst) ;; Tharwat - 28.Juk.2021 ;; (and (princ "\nSelect Main Text : ") (or (setq sel (ssget "_+.:S" '((0 . "*TEXT")))) (alert "Nothing selected on invalid object. Try again") ) (setq ssn (ssname sel 0) ins (Text:Pt_ (entget ssn)) ) (setq int -1 sel (ssget "_X" '((0 . "*TEXT"))) ) (progn (while (setq int (1+ int) ent (ssname sel int) ) (or (equal ssn ent) (setq lst (cons (list (Text:Pt_ (entget ent)) ent) lst) ) ) ) lst ) (sssetfirst nil (ssadd (cadr (cadr (vl-sort lst '(lambda (j k) (< (distance ins (car j)) (distance ins (car k))) ) ) ) ) ) ) ) (princ) ) (vl-load-com) (defun Text:Pt_ (get_) (cdr (assoc (if (or (eq "MTEXT" (cdr (assoc 0 get_))) (and (zerop (cdr (assoc 72 get_))) (zerop (cdr (assoc 73 get_))) ) ) 10 11 ) get_ ) ) ) Thank you very much for your help bro Quote
Tharwat Posted July 29, 2021 Posted July 29, 2021 14 minutes ago, ekko said: Thank you very much for your help bro You're welcome anytime. Here is a new one with a few mods for a better performance and alert. (defun c:Test (/ ssn int sel ent ins lst) ;; Tharwat - 28.Jul.2021 ;; (and (princ "\nSelect Main Text : ") (or (setq sel (ssget "_+.:S" '((0 . "*TEXT")))) (alert "Nothing selected on invalid object. Try again") ) (setq ssn (ssname sel 0) ins (Text:Pt_ (entget ssn)) ) (setq int -1 sel (ssget "_X" (list '(0 . "*TEXT") (cons 410 (getvar 'CTAB)))) ) (progn (while (setq int (1+ int) ent (ssname sel int) ) (or (equal ssn ent) (setq lst (cons (list (Text:Pt_ (entget ent)) ent) lst) ) ) ) lst ) (or (< 1 (length lst)) (alert "Number of text is less than two <!>") ) (sssetfirst nil (ssadd (cadr (cadr (vl-sort lst '(lambda (j k) (< (distance ins (car j)) (distance ins (car k))) ) ) ) ) ) ) ) (princ) ) (vl-load-com) (defun Text:Pt_ (get_) (cdr (assoc (if (or (eq "MTEXT" (cdr (assoc 0 get_))) (and (zerop (cdr (assoc 72 get_))) (zerop (cdr (assoc 73 get_))) ) ) 10 11 ) get_ ) ) ) 1 1 Quote
ekko Posted August 4, 2021 Author Posted August 4, 2021 Hello, there is a question that needs your help. I used my own code to get the nearby text, but in some cases, the obtained is not what I want. How can I modify my code to meet the requirements. (defun c:tt (/ pt pt1) (while (not (setq bztc (entsel "\nSelect text:")))) (setq bztc1 (cdr (assoc 8 (entget (car bztc))))) (setq bzwzys (cdr (assoc 7 (entget (car bztc))))) (setq pt (cdr (assoc 10 (entget (car bztc)))) ) (setq ssff (ssget "_X" (list '(1 . "*#*") (cons 8 bztc1) (cons 7 bzwzys)) ) ) (setq sslen (sslength ssff)) (setq wzzb (list)) (setq ssn -1) (repeat sslen (setq ssn (+ ssn 1)) (setq es (ssname ssff ssn) edt (entget es) ) (setq pt1 (list (cdr (assoc 10 edt)))) (setq wzzb (append pt1 wzzb)) ) (setq wzzb (cadr(vl-sort wzzb '(lambda (a b) (< (distance pt a) (distance pt b)) ) ) )) (repeat (setq i (sslength ssff)) (setq es (ssname ssff (setq i (1- i))) edt (entget es) ) (setq pt1 (cdr (assoc 10 edt)) ) (if (equal pt1 wzzb 10) (setq k1 es) ) ) (setq es (ssadd) es (ssadd k1 es)) (sssetfirst nil es) (princ) ) Quote
mhupp Posted August 4, 2021 Posted August 4, 2021 43 minutes ago, ekko said: Hello, there is a question that needs your help. I used my own code to get the nearby text, but in some cases, the obtained is not what I want. How can I modify my code to meet the requirements. Looks like 400 will always be closest to 200. If its that close why not just select the 200 you want with your mouse or is this a part of a bigger lisp to update text? Quote
BIGAL Posted August 5, 2021 Posted August 5, 2021 You may have to rework the approach using SSGET "F" this would use say 1st text then look say to the right a fixed distance so would not find a text with a different Y, another is a "CP" where you draw a extended box around the text's and look at the Y value again with a Fuzz factor/tolerance. 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.