Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 03/22/2025 in all areas

  1. Where I worked all up like 1000 pc's so you can imagine the control IT had, we were lucky and they would talk to us and fix issues mainly with file access as suggested. It ws controlled under our Group access.
    1 point
  2. My way, if can be a pleasure... (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:CalcTwoTxt ( / ss1 ss2 val1 val2 op 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) (initget "* + - /") (setq op (getkword "\nSelect an operation [*/+/-/\/]? <+>: ")) (if (not op) (setq op "+")) (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) ) NB:The extractnumber function recovers all the digital values contained in a text in the form of a list exemple: (extractnumber "area floor = 45.60m², length 12.56m heigth = 2.12m") -> (45.6 12.56 2.12)
    1 point
  3. Cold try this as a modification, keeping your method: Putting getNumericValue as a subroutine (I find that better for these forum LISPs, copy and paste 1 routine rather than several), getNumericValue altered. I didn't test for mtexts numbers over 256 characters - it should work if you really really want to. Changed the order in the main routine a bit, calculates and reports the value of the 'v's just after selection - handy to have a confirmation of the selected value just after selection Works in my quick tests (defun c:CalcTwoTxt ( / lastOp prompt op ent1 ent2 v1 v2 result inspt validOps) (defun getNumericValue (ent / edata val str1 str3) (setq edata (entget ent)) (setq val 0) (if (or (equal (cdr (assoc 0 edata)) "TEXT")(equal (cdr (assoc 0 edata)) "MTEXT")) (progn (setq val (cdr (assoc 1 edata))) (if (assoc 3 edata) (setq val (strcat str1 str3))) ) ; end progn ) (princ val) (atof val) ) (setq validOps '("*" "+" "-" "/")) (setq lastOp (getenv "CALC_TXT_LAST_OP")) (setq prompt (strcat "\nSelect an operation [*/+/-/\/] <" (if lastOp lastOp "") ">: ")) (setq op (getstring "\nSelect an operation [*/+/-/]: ")) (if (= op "") (setq op lastOp)) (if (not (member op validOps)) (progn (alert "An invalid operation. The operation is used \"+\".") (setq op "+") ) ) (setenv "CALC_TXT_LAST_OP" op) (setq ent1 (car (entsel "\nSelect the first text or MTEXT: "))) (if (null ent1) (exit)) (setq v1 (getNumericValue ent1)) (setq ent2 (car (entsel "\nSelect the second text or MTEXT: "))) (if (null ent2) (exit)) (setq v2 (getNumericValue ent2)) (cond ((= op "*") (setq result (* v1 v2))) ((= op "+") (setq result (+ v1 v2))) ((= op "-") (setq result (- v1 v2))) ((= op "/") (if (zerop v2) (setq result 0.0) (setq result (/ v1 v2)) ) ) (T (setq result 0.0)) ) (setq inspt (getpoint "\nSpecify the insertion point of the result: ")) (if (null inspt) (exit)) (command "_.TEXT" inspt "2.5" "0" (rtos result 2 2) "") (princ) )
    1 point
×
×
  • Create New...