motee-z Posted July 13, 2022 Share 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 Link to comment Share on other sites More sharing options...
mhupp Posted July 13, 2022 Share 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 Link to comment Share on other sites More sharing options...
motee-z Posted July 13, 2022 Author Share Posted July 13, 2022 Tank you mhupp that is great Quote Link to comment Share on other sites More sharing options...
ronjonp Posted July 13, 2022 Share 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 Link to comment Share on other sites More sharing options...
motee-z Posted July 13, 2022 Author Share Posted July 13, 2022 thanks Quote Link to comment Share on other sites More sharing options...
mhupp Posted July 13, 2022 Share Posted July 13, 2022 1 hour ago, ronjonp said: Another way: You misspelled Better Quote Link to comment Share on other sites More sharing options...
ronjonp Posted July 13, 2022 Share Posted July 13, 2022 5 minutes ago, mhupp said: You misspelled Better Just another way to skin the cat Quote Link to comment Share on other sites More sharing options...
ravi sharma Posted September 10, 2022 Share 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 Link to comment Share on other sites More sharing options...
Steven P Posted September 11, 2022 Share 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 Link to comment Share on other sites More sharing options...
Tharwat Posted September 11, 2022 Share 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 Link to comment Share on other sites More sharing options...
BIGAL Posted September 12, 2022 Share Posted September 12, 2022 If you sort smallest to largest (last lst) is max 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.