pyou Posted October 25, 2023 Posted October 25, 2023 Hi all Could someone help me to create a lisp, that perform arithmetical operation - subtraction only on numerical data within Text/Mtext which may include Alphabetical Prefixes, please? For example: The idea would be to click on the first text, than on the second text and the second text replacing itself with the answer, So IL0.50 should become IL11.50 and IL1.00 should become IL-0.80 First Example: CL12.00 IL0.50 Second example: CL0.20 IL1.00 Thank you Quote
mhupp Posted October 25, 2023 Posted October 25, 2023 http://www.lee-mac.com/textcalculator.html Quote
BIGAL Posted October 26, 2023 Posted October 26, 2023 (edited) This one is what you want by Lee I use it various programs regarding to strings with numbers. Example code at end. ;;-------------------=={ Parse Numbers }==--------------------;;` ;; ;; ;; Parses a list of numerical values from a supplied string. ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;; ;;------------------------------------------------------------;; ;; Arguments: ;; ;; s - String to process ;; ;;------------------------------------------------------------;; ;; Returns: List of numerical values found in string. ;; ;;------------------------------------------------------------;; (defun LM:ParseNumbers ( s ) ( (lambda ( l ) (read (strcat "(" (vl-list->string (mapcar (function (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) (list nil)) ) ) ")" ) ) ) (vl-string->list s) ) ) (defun c:wow ( / num1ent num2ent num1str num2str diff tstr) (setq num1ent (entget (car (entsel "\npick 1st text ")))) (setq num1str (cdr (assoc 1 num1ent))) (setq num1 (car (LM:ParseNumbers num1str ))) (setq num2ent (entget (car (entsel "\npick 2nd text")))) (setq num2str (cdr (assoc 1 num2ent))) (setq num2 (car (LM:ParseNumbers num2str ))) (setq diff (- num1 num2)) (setq tstr (strcat "IL " (rtos diff 2 2))) (entmod (subst (cons 1 tstr) (assoc 1 num2ent) num2ent)) (princ) ) (c:wow) Edited October 26, 2023 by BIGAL 1 Quote
pyou Posted October 26, 2023 Author Posted October 26, 2023 19 hours ago, mhupp said: http://www.lee-mac.com/textcalculator.html Its not helpful as it is way too professional and too many functions in it. Quote
pyou Posted October 26, 2023 Author Posted October 26, 2023 15 hours ago, BIGAL said: This one is what you want by Lee I use it various programs regarding to strings with numbers. Example code at end. ;;-------------------=={ Parse Numbers }==--------------------;;` ;; ;; ;; Parses a list of numerical values from a supplied string. ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;; ;;------------------------------------------------------------;; ;; Arguments: ;; ;; s - String to process ;; ;;------------------------------------------------------------;; ;; Returns: List of numerical values found in string. ;; ;;------------------------------------------------------------;; (defun LM:ParseNumbers ( s ) ( (lambda ( l ) (read (strcat "(" (vl-list->string (mapcar (function (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) (list nil)) ) ) ")" ) ) ) (vl-string->list s) ) ) (defun c:wow ( / num1ent num2ent num1str num2str diff tstr) (setq num1ent (entget (car (entsel "\npick 1st text ")))) (setq num1str (cdr (assoc 1 num1ent))) (setq num1 (car (LM:ParseNumbers num1str ))) (setq num2ent (entget (car (entsel "\npick 2nd text")))) (setq num2str (cdr (assoc 1 num2ent))) (setq num2 (car (LM:ParseNumbers num2str ))) (setq diff (- num1 num2)) (setq tstr (strcat "IL " (rtos diff 2 2))) (entmod (subst (cons 1 tstr) (assoc 1 num2ent) num2ent)) (princ) ) (c:wow) Thank you BIGAL, Just like I have imagined! wow Quote
pyou Posted October 26, 2023 Author Posted October 26, 2023 (edited) BIGAL, may I ask if we could tweak it slightly? 1) To Change the colour of the selected entities to the RGB colour (255, 0, 0) - basically so it could stand out. 2) It may be not only ''IL'' prefix, but also any other alphabets, for example WL or SL - for some reason it replaces WL1.00 to IL 1.00 Edited October 26, 2023 by pyou Quote
BIGAL Posted October 27, 2023 Posted October 27, 2023 I did not look at prefix so will need a code edit. will see what I can do. 1 Quote
pyou Posted October 29, 2023 Author Posted October 29, 2023 On 27/10/2023 at 05:44, BIGAL said: I did not look at prefix so will need a code edit. will see what I can do. Thank you BIGAL Quote
pyou Posted October 30, 2023 Author Posted October 30, 2023 (edited) I have found the solution. Edited October 31, 2023 by pyou 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.