Tsuky Posted Sunday at 10:17 AM Posted Sunday at 10:17 AM (edited) On 3/22/2025 at 6:47 AM, Nikon said: @Tsuky HUGE thank. The division operation is active, but there is one drawback. Dividing a smaller number by a larger one gives 0. For example, 5/10=0 or 5/550=0... decimal division works fine 05./50.5=0.9. ??? Is it possible to remember the last choice of operation? Expand If you submit integers to the divide function, the result will be an integer. See help ... This is possible: remove the variable "op" from local variables, which could give: (defun c:CalcTwoTxt ( / ss1 ss2 val1 val2 key rslt inspt) (princ "\nSelect first text") (while (not (setq ss1 (ssget "_+.:E:S" '((0 . "*TEXT")))))) (princ "\nSelect second text") (while (not (setq ss2 (ssget "_+.:E:S" '((0 . "*TEXT")))))) (setq val1 (extractnumber (cdr (assoc 1 (entget (ssname ss1 0)))))) (setq val2 (extractnumber (cdr (assoc 1 (entget (ssname ss2 0)))))) (cond ((and val1 val2) (if (not op) (setq op "+")) (initget "* + - /") (setq key (getkword (strcat "\nSelect an operation [*/+/-/\/]? <" op ">: "))) (if key (setq op key)) (if (and (eq op "/") (member 0 val2)) (setq rslt 0.0) (setq rslt (apply (read op) (append val1 val2))) ) (initget 1) (setq inspt (getpoint "\nSpecify the insertion point of the result: ")) (command "_.TEXT" inspt "2.5" "0" (rtos rslt 2 2)) ) (T (princ "\No value found in text")) ) (prin1) ) Edited Sunday at 10:36 AM by Tsuky 1 Quote
Nikon Posted Sunday at 11:02 AM Author Posted Sunday at 11:02 AM (edited) On 3/23/2025 at 10:17 AM, Tsuky said: f you submit integers to the divide function, the result will be an integer. See help ... This is possible: remove the variable "op" from local variables, which could give: Expand The code with the added function EXTRACTNUMBER. (defun ExtractNumber (str / l rslt) (setq l (mapcar '(lambda (x) (if (and (> x 44) (< x 58) (/= x 47)) x 32) ) (vl-string->list str) ) l (mapcar '(lambda (x y) (if (not (= x y 32)) x) ) l (append (cdr l) '(32)) ) l (vl-remove-if-not '(lambda (x) (eq (type x) 'INT) x) l) l (mapcar '(lambda (x) (if (not (eq x 32)) x (list nil))) l) ) (eval (read (strcat "(setq rslt (list " (apply 'strcat (mapcar '(lambda (x) (if (not (listp x)) (chr x) " ")) l)) "))"))) ) (defun c:Calc2TxtTsk ( / ss1 ss2 val1 val2 key rslt inspt) (princ "\nSelect first text") (while (not (setq ss1 (ssget "_+.:E:S" '((0 . "*TEXT")))))) (princ "\nSelect second text") (while (not (setq ss2 (ssget "_+.:E:S" '((0 . "*TEXT")))))) (setq val1 (extractnumber (cdr (assoc 1 (entget (ssname ss1 0)))))) (setq val2 (extractnumber (cdr (assoc 1 (entget (ssname ss2 0)))))) (cond ((and val1 val2) (if (not op) (setq op "+")) (initget "* + - /") (setq key (getkword (strcat "\nSelect an operation [*/+/-/\/]? <" op ">: "))) (if key (setq op key)) (if (and (eq op "/") (member 0 val2)) (setq rslt 0.0) (setq rslt (apply (read op) (append val1 val2))) ) (initget 1) (setq inspt (getpoint "\nSpecify the insertion point of the result: ")) (command "_.TEXT" inspt "2.5" "0" (rtos rslt 2 2)) ) (T (princ "\No value found in text")) ) (prin1) ) Edited Sunday at 03:32 PM by Nikon function EXTRACTNUMBER added Quote
Steven P Posted Sunday at 11:04 AM Posted Sunday at 11:04 AM So to first principles.... "No function definition" means it is looking for a function "ExtractNumber", I wonder if this was elsewhere in this thread. Quote
Steven P Posted Sunday at 11:48 AM Posted Sunday at 11:48 AM No, the confused doesn't work... at 400+ posts it wold be reasonable expectation for you to look back at Tsukys other posts to see if the missing LISP function is in there. Quote
Nikon Posted Sunday at 12:07 PM Author Posted Sunday at 12:07 PM (edited) The function EXTRACTNUMBER has been added. The code works. Thanks! Edited Sunday at 03:30 PM by Nikon 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.