notview Posted September 28, 2014 Share Posted September 28, 2014 Any help, is this possible to add numbers all selected numbers at once? Example, I have 11, 22, 33, 44, 55 numbers. After I select this 5 numbers it will give the sum of 165. Quote Link to comment Share on other sites More sharing options...
7o7 Posted September 28, 2014 Share Posted September 28, 2014 Try this. (defun c:test () (apply '+ (mapcar '(lambda (x) (distof (cdr (assoc 1 (entget x))))) (vl-remove-if-not '(lambda(x) (distof (cdr (assoc 1 (entget x))))) (vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget '((0 . "TEXT"))))))))) ) Quote Link to comment Share on other sites More sharing options...
notview Posted September 28, 2014 Author Share Posted September 28, 2014 Thanks 7o7, It works perfect in integer!! although, having number with 4 decimal places are not working.. Quote Link to comment Share on other sites More sharing options...
Stefan BMR Posted September 28, 2014 Share Posted September 28, 2014 Maybe you are using the wrong decimal separator, "," instead of "." or vice versa. Try (distof "1.1") and (distof "1,1"), check your texts and replace if necessary. Quote Link to comment Share on other sites More sharing options...
7o7 Posted September 28, 2014 Share Posted September 28, 2014 Can you post a file with your numbers to see how they are? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 28, 2014 Share Posted September 28, 2014 Perhaps the resulting number is truncated, try the following: (defun c:sumtxt ( / i r s ) (setq r 0) (if (setq s (ssget (cons '(0 . "TEXT") (kg:SsgetFilterNum)))) (repeat (setq i (sslength s)) (setq r (+ r(atof (cdr (assoc 1 (entget (ssname s (setq i (1- i))))))))) ) ) (princ (strcat "\nTotal: " (rtos r))) (princ) ) (defun kg:SsgetFilterNum ( ) ;; roy '( (1 . "~*[~-.0-9]*") ; only minus signs, decimal points and numbers allowed (1 . "~*`.*`.*") ; only one decimal point allowed (-4 . "<OR") (1 . "~*-*") ; there is no minus sign (-4 . "<AND") (1 . "-*") ; the minus sign must be the first character (1 . "~*-*-*") ; only one minus sign allowed (-4 . "AND>") (-4 . "OR>") ) ) (princ) The above will format the result based on your LUNITS & LUPREC settings. Quote Link to comment Share on other sites More sharing options...
notview Posted September 28, 2014 Author Share Posted September 28, 2014 Thanks for comments SBMR.. Sometimes, there are numbers written with comma as thousand separator, like: 12,123.1111 34,345.3333 on so on.. Is there way to add this numbers with same procedure select all numbers and add? any help.. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 28, 2014 Share Posted September 28, 2014 Thanks for comments SBMR.. Sometimes, there are numbers written with comma as thousand separator, like: 12,123.1111 34,345.3333 on so on.. Is there way to add this numbers with same procedure select all numbers and add? any help.. A quick mod of my above posted code: (defun c:sumtxt ( / i r s ) (setq r 0) (if (setq s (ssget (cons '(0 . "TEXT") (kg:SsgetFilterNum)))) (repeat (setq i (sslength s)) (setq r (+ r (atof (vl-list->string (vl-remove 44 (vl-string->list (cdr (assoc 1 (entget (ssname s (setq i (1- i)))))))))))) ) ) (princ (strcat "\nTotal: " (rtos r))) (princ) ) (defun kg:SsgetFilterNum ( ) ;; roy (tweaked by Lee Mac to allow commas) '( (1 . "~*[~-.,0-9]*") ; only minus signs, decimal points, commas and numbers allowed (1 . "~*`.*`.*") ; only one decimal point allowed (-4 . "<OR") (1 . "~*-*") ; there is no minus sign (-4 . "<AND") (1 . "-*") ; the minus sign must be the first character (1 . "~*-*-*") ; only one minus sign allowed (-4 . "AND>") (-4 . "OR>") ) ) Quote Link to comment Share on other sites More sharing options...
notview Posted September 28, 2014 Author Share Posted September 28, 2014 THANKS!! LM, your code written is better one!! It gives sum depending on the given number precision.. However, numbers as I post above, #7, gave a Total =0.0000.. Is there a way to add that numbers? (I'm referring post #7) Quote Link to comment Share on other sites More sharing options...
notview Posted September 28, 2014 Author Share Posted September 28, 2014 CHEERS!!!! HAHAHA!! It is working FINE!! VERY PERFECT!! THANK YOU LEE MAC, your code is very powerful!! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 28, 2014 Share Posted September 28, 2014 You're welcome notview, happy to help. 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.