CAD2005 Posted May 7, 2025 Posted May 7, 2025 (edited) Hi everybody. I found this lisp on the forum This lisp is for Sum text, but this lisp only add interger part please review lisp and correct the decimal , example : 2000,35 + 1000,55 = 3000,90 thank you for your help (defun C:STX (/ cpent elist en ip newtxt pt ss sum sumtxt txt) (princ "\n\t\t>>> Select text to get summ >>>") (if ;;select texts/mtexts on screen : (setq ss (ssget '((0 . "*TEXT")))) ;; if selected then : (progn ;; store the first text entity for using 'em further : (setq cpent (ssname ss 0)) ;; set initial sum to zero : (setq sum 0.) ;; loop trough selected texts/mtexts : (while ;; get the first text in selection : (setq en (ssname ss 0)) ;; get entity list of them : (setq elist (entget en)) ;; get the textstring by key 1 from entity list : (setq txt (cdr (assoc 1 elist))) ;; create output string : (setq sumtxt ;; concatenate strings : (strcat ;; convert digits to string : (rtos ;; add to summ the digital value of text : (setq sum (+ (atof txt) sum)) ;; 2 is for metric units (3 for engineering) : 2 ;; set precision by current : (getvar "dimdec"))) ) ;; delete entity from selection set : (ssdel en ss) ) ;; display message in the command line: (princ (strcat "\nSumm=" sumtxt)) (setq pt (getpoint "\nSpecify the new text location: ")) ;; get the insertion point of stored entity : (setq ip (cdr (assoc 10 (entget cpent)))) ;; copy text entity to the new destination point : (command "_copy" cpent "" ip pt) ;; get the last created entity : (setq newtxt (entlast)) ;; get entity list of them : (setq elist (entget newtxt)) ;; modify entity list with new text string : (entmod (subst (cons 1 sumtxt)(assoc 1 elist) elist)) ;; update changes : (entupd newtxt) ) ) (princ) ) (princ "\nStart command with STX...") (princ) Edited May 7, 2025 by SLW210 Added Code Tags!! Quote
Emmanuel Delay Posted May 7, 2025 Posted May 7, 2025 These are not considered numbers: 2000,35 + 1000,55 = 3000,90 These are considered numbers: 2000.35 + 1000.55 = 3000.90 Anyway, A added 2 commands. STXC if you use commas as the decimal point. STXP if you use fullstop character ( "." ) as the decimal point. (vl-load-com) (setq use_comma_as_decimal_point nil) ;; With comma (defun C:STXC ( / ) (setq use_comma_as_decimal_point T) (C:STX) ) ;; With fullstop character (defun C:STXP ( / ) (setq use_comma_as_decimal_point nil) (C:STX) ) (defun C:STX (/ cpent elist en ip newtxt pt ss sum sumtxt txt) (princ "\n\t\t>>> Select text to get summ >>>") (if ;;select texts/mtexts on screen : (setq ss (ssget '((0 . "*TEXT")))) ;; if selected then : (progn ;; store the first text entity for using 'em further : (setq cpent (ssname ss 0)) ;; set initial sum to zero : (setq sum 0.) ;; loop trough selected texts/mtexts : (while ;; get the first text in selection : (setq en (ssname ss 0)) ;; get entity list of them : (setq elist (entget en)) ;; get the textstring by key 1 from entity list : (setq txt (cdr (assoc 1 elist))) (if use_comma_as_decimal_point ;; replace comma by fullstop (setq txt (vl-string-subst "." "," txt)) ) ;; create output string : (setq sumtxt ;; concatenate strings : (strcat ;; convert digits to string : (rtos ;; add to summ the digital value of text : (setq sum (+ (atof txt) sum)) ;; 2 is for metric units (3 for engineering) : 2 ;; set precision by current : (getvar "dimdec") ) ) ) ;; delete entity from selection set : (ssdel en ss) ) ;; display message in the command line: (princ (strcat "\nSumm=" sumtxt)) (setq pt (getpoint "\nSpecify the new text location: ")) ;; get the insertion point of stored entity : (setq ip (cdr (assoc 10 (entget cpent)))) ;; copy text entity to the new destination point : (command "_copy" cpent "" ip pt) ;; get the last created entity : (setq newtxt (entlast)) ;; get entity list of them : (setq elist (entget newtxt)) (if use_comma_as_decimal_point ;; replace fullstop by comma (setq sumtxt (vl-string-subst "," "." sumtxt)) ) ;; modify entity list with new text string : (entmod (subst (cons 1 sumtxt)(assoc 1 elist) elist)) ;; update changes : (entupd newtxt) ) ) (princ) ) (princ "\nStart command with STX...") (princ) Quote
CAD2005 Posted May 7, 2025 Author Posted May 7, 2025 Thank you @Emmanuel Delay! but I tried it and it didn't give the odd part. Quote
Emmanuel Delay Posted May 7, 2025 Posted May 7, 2025 (edited) What this code does: you select TEXT elements. Each TEXT is supposed to only hold a numeric value. Then a sum is made of each of the selected numbers. Then you pick a point where the new TEXT comes, with the summed value. Here's an example sum_texts.lsp.dwg Edited May 7, 2025 by Emmanuel Delay Quote
SLW210 Posted May 7, 2025 Posted May 7, 2025 Please place code in code tags! (<> in the editor toolbar) Quote
CAD2005 Posted May 7, 2025 Author Posted May 7, 2025 Thank You very much for this help @Emmanuel Delay thank you . 1 Quote
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.