motee-z Posted July 13, 2022 Posted July 13, 2022 I need a lisp that can find maximum value number in a selection contain numbers and text sting any help will be appreciated Quote
mhupp Posted July 13, 2022 Posted July 13, 2022 (edited) convert strings to numbers with atof add it to a list use vl-sort > on list output first number in list ;;----------------------------------------------------------------------------;; ;;List Maximum Value (defun C:MValue (/ ss txt lst) (if (setq ss (ssget '((0 . "*TEXT")))) (foreach txt (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS))) (setq value (atof (cdr (assoc 1 (entget txt))))) (setq lst (cons value lst)) (setq lst (vl-sort lst '>)) ) ) (prompt (strcat "\nMaximum Value: " (rtos (car lst) 2))) (princ) ) --Edit If your strings contain letters and numbers might have to do a little more before atof Edited July 13, 2022 by mhupp 1 Quote
ronjonp Posted July 13, 2022 Posted July 13, 2022 Another way: (defun c:foo (/ ss) (if (setq ss (ssget '((0 . "*TEXT")))) (print (apply 'max (mapcar '(lambda (x) (atof (cdr (assoc 1 (entget x))))) (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))) ) ) ) ) (princ) ) 2 Quote
mhupp Posted July 13, 2022 Posted July 13, 2022 1 hour ago, ronjonp said: Another way: You misspelled Better Quote
ronjonp Posted July 13, 2022 Posted July 13, 2022 5 minutes ago, mhupp said: You misspelled Better Just another way to skin the cat Quote
ravi sharma Posted September 10, 2022 Posted September 10, 2022 On 14/07/2022 at 00:37, mhupp said: convert strings to numbers with atof add it to a list use vl-sort > on list output first number in list ;;----------------------------------------------------------------------------;; ;;List Maximum Value (defun C:MValue (/ ss txt lst) (if (setq ss (ssget '((0 . "*TEXT")))) (foreach txt (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS))) (setq value (atof (cdr (assoc 1 (entget txt))))) (setq lst (cons value lst)) (setq lst (vl-sort lst '>)) ) ) (prompt (strcat "\nMaximum Value: " (rtos (car lst) 2))) (princ) ) --Edit If your strings contain letters and numbers might have to do a little more before atof is there any possibility to keep highest vale and remove remaining? please suggest,. Quote
Steven P Posted September 11, 2022 Posted September 11, 2022 If you have all the values as a list, largest first you could try a very simple from MHUPPS example (setq lst (car lst)) of (setq lst (nth 0 lst)) Both set the variable lst to the first value in that list and deletes all the others I think RonJonp offered a solution that does the same , Replace (print with (setq maxvalue 1 Quote
Tharwat Posted September 11, 2022 Posted September 11, 2022 On 9/10/2022 at 10:25 AM, ravi sharma said: is there any possibility to keep highest vale and remove remaining? please suggest,. Are you the same user posted in Autodesk forum ? https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/keep-only-highest-value-text-in-selected-text/td-p/11412722 Quote
BIGAL Posted September 12, 2022 Posted September 12, 2022 If you sort smallest to largest (last lst) is max 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.