keep only highest value text in selected text.

keep only highest value text in selected text.

ravi82sharm
Explorer Explorer
598 Views
3 Replies
Message 1 of 4

keep only highest value text in selected text.

ravi82sharm
Explorer
Explorer

Hello, I have so many bunches of text and want to keep only the highest value in it. can anyone suggest to me the lisp for the same? thank you in advance.

0 Likes
Accepted solutions (1)
599 Views
3 Replies
Replies (3)
Message 2 of 4

hak_vz
Advisor
Advisor
Accepted solution

Since you didn't  provided sample dwg here is code that works with selected text without filtering. Let suppose all selected text  has numerical values. To use this code move text entities aside or leave only this layer on.

(defun c:maxvaluetext ( / ss i lst)
	(setq  i -1 ss (ssget '((0 . "*text"))))
	(cond 
		((and ss)
			(while (< (setq i (1+ i)) (sslength ss))
				(setq lst (cons (list (atof(cdr(assoc 1 (entget (ssname ss i))))) (ssname ss i)) lst))
			)
			(mapcar 'entdel (mapcar 'cadr (cdr (vl-sort lst '(lambda (x y) (> (car x)(car y)))))))
		)
	)
	(princ)
)

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 3 of 4

ravi82sharm
Explorer
Explorer

thank you it works. yes all values are numeric.

0 Likes
Message 4 of 4

_Tharwat
Advisor
Advisor

Another way using AutoLISP vanilla.

 

(defun c:Test (/ int sel ent num big del)
  ;; Tharwat - Date: 10.Sep.2022	;;
  (and (princ "\nSelect texts : ")
       (setq int -1 sel (ssget "_:L" '((0 . "TEXT,MTEXT") (1 . "*#*"))))
       (while (setq int (1+ int) ent (ssname sel int))
         (or (and (setq num (distof (cdr (assoc 1 (entget ent)))))
                  (> num big)
                  (if del (entdel del) t)
                  (setq big num del ent)
                  )
             (entdel ent)
             )
         )
       )
  (princ)
  )

 

 

 

0 Likes