mousho Posted April 10, 2022 Posted April 10, 2022 hello guys i have a great lisp that i found in the website for combinning values anyone can help me to change it from single selection (entsel) to selection by window (ssget) i try few times with no success CombineValues.LSP Quote
mhupp Posted April 10, 2022 Posted April 10, 2022 (edited) That's going to take more then just switching out (entsel) I'm guessing you just want the total sum? lisp was edited from here *text must be only numbers or it will be ignored. (defun C:TXTSUM (/ sum ss en txt sumtxt) (princ "\nSelect Text to get Sum:") (setq sum 0) (if (and (setq ss (ssget '((0 . "*TEXT")))) (> (sslength ss) 1)) (progn (foreach en (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS))) (setq txt (cdr (assoc 1 (entget en)))) (if (distof txt) (setq sumtxt (rtos (setq sum (+ (atof txt) sum)) 2 (getvar "dimdec"))) (progn (setq txt (LM:parsenumbers txt)) (foreach num txt (setq sumtxt (rtos (setq sum (+ num sum)) 2 (getvar "dimdec"))) ) ) ) ) (prompt (strcat "\nTotal Sum: " sumtxt)) ) ) (princ) ) ;; Parse Numbers - Lee Mac ;; Parses a list of numerical values from a supplied string. ;; Author: Lee Mac, Copyright © 2013 - www.lee-mac.com ;; ;;------------------------------------------------------------;; (defun LM:parsenumbers (str) ((lambda (l) (read (strcat "(" (vl-list->string (mapcar '(lambda (a b c) (if (or (< 47 b 58) (and (= 45 b) (< 47 c 58) (not (< 47 a 58))) (and (= 46 b) (< 47 a 58) (< 47 c 58)) ) b 32 ) ) (cons nil l) l (append (cdr l) '(())) ) ) ")" ) ) ) (vl-string->list str) ) ) Edited April 11, 2022 by mhupp Code Updated Quote
mousho Posted April 10, 2022 Author Posted April 10, 2022 2 hours ago, mhupp said: That's going to take more then just switching out (entsel) I'm guessing you just want the total sum? lisp was edited from here *text must be only numbers or it will be ignored. (defun C:TXTSUM (/ elist en ss sum sumtxt txt ins) (princ "\nSelect Text to get Sum:") (setq sum 0) (if (and (setq ss (ssget '((0 . "*TEXT")))) (> (sslength ss) 1)) (progn (foreach en (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS))) (setq elist (entget en)) (setq txt (cdr (assoc 1 elist))) (setq sumtxt (rtos (setq sum (+ (atof txt) sum)) 2 (getvar "dimdec"))) ) (prompt (strcat "\nTotal Sum: " sumtxt)) ) ) (princ) ) THX But the other lisp is reading from xref and its very helpfull Quote
mhupp Posted April 10, 2022 Posted April 10, 2022 Yes it is. You cant do ssget with nested items. Quote
Tharwat Posted April 10, 2022 Posted April 10, 2022 1 hour ago, mhupp said: Yes it is. You cant do ssget with nested items. But you can explore it as if it is a block reference. Quote
BIGAL Posted April 11, 2022 Posted April 11, 2022 You can get the numbers from a string. eg "area = 1224" ;; Parse Numbers - Lee Mac ;; Parses a list of numerical values from a supplied string. ;; Author: Lee Mac, Copyright © 2013 - www.lee-mac.com ;; ;;------------------------------------------------------------;; (defun LM:parsenumbers ( str ) ( (lambda ( l ) (read (strcat "(" (vl-list->string (mapcar '(lambda ( a b c ) (if (or (< 47 b 58) (and (= 45 b) (< 47 c 58) (not (< 47 a 58))) (and (= 46 b) (< 47 a 58) (< 47 c 58)) ) b 32 ) ) (cons nil l) l (append (cdr l) '(())) ) ) ")" ) ) ) (vl-string->list str) ) ) 1 Quote
mhupp Posted April 11, 2022 Posted April 11, 2022 On 4/10/2022 at 7:08 AM, mousho said: THX But the other lisp is reading from xref and its very helpfull So your going to have to either copy the xref to a new location and explode it or enter into edit mode. If it doesn't have any other blocks inside. You can then select all of the text you want and run the lisp to get a total sum. Added Lee Mac's code to what i had above. Quote
exceed Posted April 12, 2022 Posted April 12, 2022 (edited) This is one of the cheat for converting code written in entsel to ssget. (defun c:ssgetentsel () (setq exss (ssget)) (setq exssl (sslength exss)) (setq exssindex 0) (repeat exssl (setq exssent (entget (ssname exss exssindex))) (setq makeentsel1 (cdr (car exssent))) (setq makeentsel2 (cdr (assoc 10 exssent))) (setq makeentsel (list makeentsel1 makeentsel2)) (princ makeentsel) ; do something (setq exssindex (+ exssindex 1)) ) (princ) ) And you can access the object in the block with the nametolist and while statements here. Get your text from there. I used this for my make it color Lisp, but it gave me a headache. It would be better to solve it with other people's solutions above. However, since it is difficult to select the target text from a block or xref, the solutions of others above seem more appropriate. (or can be easy if the text has a specific prefix or suffix attached to it) Edited April 12, 2022 by exceed 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.