Cad64 Posted April 11, 2012 Share Posted April 11, 2012 Hey guys, I'm looking for a routine that will add up the total of selected dtext numbers. These numbers are large square footage totals like 47,604.27 and 23,705.39. I have the routine below, (that I got from the Cadalyst site), but it treats the commas like decimal points and rounds off to the nearest whole number. So when it adds the two amounts above it returns a total of 70.0 instead of 71,309.66. If anyone has a routine, or can modify the routine below so that it can add large numbers with commas, and not round off the total, I will be forever grateful. Thanks for your time. ;Tip1369A.LSP: ADD.LSP Add Selected Numbers (P.K.Yousuf) ;Prepared by P.K.Yousuf (defun C:ADD (/ S1 LG INDEX A B C D) (setq S1 (ssget) LG (sslength S1) INDEX 0 C 0 ) ;_ end of setq (while (/= INDEX LG) (setq A (entget (ssname S1 INDEX)) D (cdr (assoc 0 A)) ) ;_ end of setq (if (= D "TEXT") (progn (setq B (atof (cdr (assoc 1 A))) C (+ C B) ) ;_ end of setq ) ;_ end of progn ) ;_ end of if (setq INDEX (1+ INDEX)) ) ;_ end of while (princ "\nTotal Value: ") (princ C) (princ) ) ;end defun Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 11, 2012 Share Posted April 11, 2012 Give this a try: (defun c:AddText ( / i r s x ) (if (setq s (ssget '((0 . "TEXT") (1 . "*#*")))) (progn (setq r 0.0) (repeat (setq i (sslength s)) (setq x (cdr (assoc 1 (entget (ssname s (setq i (1- i))))))) (while (wcmatch x "*`,*") (setq x (vl-string-subst "" "," x)) ) (if (setq x (distof x)) (setq r (+ r x)) ) ) (princ (strcat "\nTotal: " (rtos r))) ) ) (princ) ) The printed result will be dependent on your settings of LUNITS / LUPREC Quote Link to comment Share on other sites More sharing options...
Cad64 Posted April 11, 2012 Author Share Posted April 11, 2012 Thanks a lot Lee, it works perfectly. As usual, you are the man. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 11, 2012 Share Posted April 11, 2012 Cheers Rod, you're very welcome Quote Link to comment Share on other sites More sharing options...
pBe Posted April 11, 2012 Share Posted April 11, 2012 Whilst i was trying to figure out what to do with the "," thingy. Lee came and went. **** Gone in 60 seconds **** Nice code btw Lee Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 11, 2012 Share Posted April 11, 2012 Cheers pBe 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.