tnvsb Posted October 5, 2018 Posted October 5, 2018 Dear All, I got a lisp code that is well working for summation of number with suffix alphabets, but not working for numbers with prefix alphabets. Please have a look on attachments and below lisp code. (defun C:ADCC (/ 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) SUMMATION OF NUMBERS WITH PREFIX ALPHABETS.dwg Quote
Tharwat Posted October 5, 2018 Posted October 5, 2018 Here you go with two more AutoLISP forums that you did not post in them yet. http://www.autolisp.com/forum/autocad/autolisp https://www.theswamp.org/index.php?board=2.0 Quote
tnvsb Posted October 5, 2018 Author Posted October 5, 2018 57 minutes ago, Tharwat said: Here you go with two more AutoLISP forums that you did not post in them yet. http://www.autolisp.com/forum/autocad/autolisp https://www.theswamp.org/index.php?board=2.0 But My organization blocked those websites, so can't post. 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.