sivapathasunderam Posted February 12, 2023 Posted February 12, 2023 Sum of selected text values at once & place total figure at pick point cad file is attached Ask forum1.dwg Quote
Aditya Bagaskara Posted February 12, 2023 Posted February 12, 2023 ;Sum of numbers (setq ents (ssget)) ;; Get all the text entities (setq sum nil nums nil ) (setq count1 0) (while (< count1 (sslength ents)) (setq nums (cons (atof (cdr (assoc 1 (entget (ssname ents count1))))) nums)) ;; Insert the value of the text into a list (setq count1 (1+ count1)) ) (setq sum (apply '+ nums)) ;; Add them all (entmake (list (cons 0 "TEXT") (cons 1 (rtos sum)) (cons 10 (getpoint)) (cons 40 (getvar "TEXTSIZE")))) ;; Make a single line that will be placed at the cursor Here is my solution. If anyone that sees this has a better solution, feel free to correct me. Hope that helps! 2 Quote
Steven P Posted February 12, 2023 Posted February 12, 2023 Might consider a filter on the ssget to select only text and mtexts? Quote
Aditya Bagaskara Posted February 12, 2023 Posted February 12, 2023 6 minutes ago, Steven P said: Might consider a filter on the ssget to select only text and mtexts? I don't know how to do that, sorry ... Quote
sivapathasunderam Posted February 12, 2023 Author Posted February 12, 2023 11 minutes ago, Aditya Bagaskara said: I don't know how to do that, sorry ... Like this ! (setq ss (ssget "_:L" '((0 . "TEXT,MTEXT")))) 3 Quote
Steven P Posted February 12, 2023 Posted February 12, 2023 3 hours ago, Aditya Bagaskara said: I don't know how to do that, sorry ... this is a good reference: http://lee-mac.com/ssget.html Quote
mhupp Posted February 12, 2023 Posted February 12, 2023 (edited) Don't need to limit things not no locked layers since your just reading the values, and (0 . "TEXT,MTEXT") can be shorted to just (0 . "*TEXT") This will allow you to select any text. it will only add up text that is only numbers. since distof will only work if the string is only numbers. ;;----------------------------------------------------------------------------;; ;;Sum of selected text that is only numbers (defun C:foo (/ sum ss) (setq sum 0) (setq SS (ssget '((0 . "*TEXT") (1 . "*#*")))) (foreach text (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS))) (if (setq x (distof (cdr (assoc 1 (entget text)))) (setq sum (+ x sum)) ) ) ) (entmake (list (cons 0 "TEXT") (cons 1 (rtos sum 2 3)) (cons 10 (getpoint)) (cons 40 (getvar "TEXTSIZE")))) (princ) ) Edited February 13, 2023 by mhupp 3 Quote
devitg Posted February 12, 2023 Posted February 12, 2023 Just for curiosity, there is a way to filter text if they only hold numbers and decimal separator, by DXF code 1? Quote
mhupp Posted February 12, 2023 Posted February 12, 2023 (edited) mmm I guess would limit text that have numbers in it. only numbers IDK. (setq SS (ssget '((0 . "*TEXT") (1 . "*#*")))) -Edit This says any text that doesn't have a letters in it. (setq SS (ssget '((0 . "*TEXT") (1 . "~*@*")))) -Edit2 I guess you could then check them against each other and keep the ones that are in both. if you really wanted to be sure. Wildcards Edited February 12, 2023 by mhupp 1 Quote
Steven P Posted February 13, 2023 Posted February 13, 2023 (edited) From MHUPPs idea, try this: Added in Dimensions for my own use (I had something that worked, and then saw a better method and now want to spend time making mine better again) (setq SS (ssget '( (-4 . "<OR") (-4 . "<AND") (0 . "*TEXT") (-4 . "<AND") (1 . "*#*") (1 . "~*@*") (-4 . "AND>") (-4 . "AND>") ; maybe too many ANDs here (-4 . "<AND") (0 . "DIMENSION") (-4 . "AND>") (-4 . "OR>") ) )) ; end ssget, setq Edited February 13, 2023 by Steven P 1 Quote
mhupp Posted February 13, 2023 Posted February 13, 2023 This. but it doesn't solve the problem just makes one big selection set. (setq SS (ssget '((0 . "*TEXT,DIMENSION") (1 . "*#*,~*@*")))) Need to find the entities that are only in both selection sets. texts that have numbers but don't have any letters. and unless your going to process a lot of text. I think it might be a wash. Since distof weeds out the text you can't use. but you can look at this and pull a few functions so you can process text that have letters and numbers. (if (setq SS (ssget '((0 . "*TEXT,DIMENSION") (1 . "*#*")))) (progn (if (setq SS1 (ssget "_P" '((0 . "*TEXT,DIMENSION") (1 . "~*@*")))) (foreach text (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS1))) (if (ssmemb text ss) (ssadd text ss2) ) ) ) ) ) 3 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.