Jump to content

Recommended Posts

Posted

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.

Posted

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")))))))))
 )

Posted

Thanks 7o7, It works perfect in integer!! although, having number with 4 decimal places are not working..

Posted

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.

Posted

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.

Posted

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..

Posted
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>")
   )
)

Posted

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)

Posted

CHEERS!!!! HAHAHA!! It is working FINE!! VERY PERFECT!!

THANK YOU LEE MAC, your code is very powerful!!

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...