Jump to content

Select all text numbers then add


notview

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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