TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: econnerly on October 18, 2011, 03:45:10 PM
-
I need a lisp routine that will add or subtract to modify a value in a text string. Its used for drainage fixture units on waste & vent plans.
Example:
We use basic dtext strings that look like this 4"(6)
I would like to be able to add or subtract to the number that is ONLY in parenthesis and would like to be able to pick multiple text strings at one time so it would result in something like this:
4"(6) + 9 will become 4"(15)
Does anyone have anything that can do something like this? I have a code that I have tried to modify, but have had no success.
-
Welcome to the Swamp.
See attached a modified (for you use) version of my Text Increment routine.
-
Nice! You my friend are the man! Only one thing. Would it be quick to modify that so I can build a selection set, run your lisp, and apply it by using "P" for previous?
-
Here's a quick one to work with your example:
(defun c:num (/ e el i n ss str)
(vl-load-com)
(defun _addbetween (string chr1 chr2 number / l1 l2 n p)
(if (and (setq l1 (vl-string-position (ascii chr1) string))
(setq l2 (vl-string-position (ascii chr2) string))
(setq n (atoi (substr string (+ l1 2) (- l2 3))))
)
(strcat (substr string 1 (1+ l1)) (itoa (+ number n)) (substr string (1+ l2)))
string
)
)
(setq i -1)
(and (setq n (getint "\nEnter number to add: "))
(setq ss (ssget ":l" '((0 . "text") (1 . "*(*)*"))))
(while (setq e (ssname ss (setq i (1+ i))))
(setq el (entget e))
(setq str (cdr (assoc 1 el)))
(entmod (subst (cons 1 (_addbetween str "(" ")" n)) (assoc 1 el) el))
)
)
(princ)
)
-
Nice! You my friend are the man! Only one thing. Would it be quick to modify that so I can build a selection set, run your lisp, and apply it by using "P" for previous?
Modified the 33 special so try it again. (Very little testing.)
-
PERFECT! Thank you so very much. This is going to save me a huge amount of time!
-
(defun c:test ( / popit ss str num str_)
(vl-load-com)
(defun popit (lst / a b c)
(while (setq a (car lst))
(setq b (cdr lst))
(if (= a 40)
(setq c
(vl-remove-if-not '(lambda (j)
(or (and (>= j 48)
(<= j 57))
(= j 41))) b)))
(setq lst b))
(atoi (vl-list->string c)))
(if (not val) (setq val 1))
(setq val (cond
((getint (strcat "\nEnter Value < " (itoa val) " >: ")))
(val)))
(setq ss (ssget ":L" '((0 . "*TEXT") (1 . "*(*)*"))))
(repeat (sslength ss)
(setq str (entget (ssname ss 0)))
(setq num (popit (vl-string->list
(setq str_ (cdr (assoc 1 (entget (ssname ss 0)))))
)
)
)
(vla-put-textstring (vlax-ename->vla-object (ssname ss 0))
(vl-string-subst
(strcat "(" (itoa (+ num val)) ")")
(strcat "(" (itoa num) ")") str_))
(setq ss (ssdel (ssname ss 0) ss))
)
(princ)
)
EDIT: modified for multiple selection
-
Wow... even better! Thank you!
-
Wow... even better! Thank you!
IMO .. that's not better than CAB's solution as his will honor real numbers as well. 8-)
-
Wow... even better! Thank you!
IMO .. that's not better than CAB's solution as his will honor real numbers as well. 8-)
Very good point. Im keeping them both. Im currently at a MEP firm and they tend to only use integers. I'm normally in a civil design positions where CAB's routine would reign superior.
-
IMO .. that's not better than CAB's solution as his will honor real numbers as well. 8-)
That is correct. cant argue with that. :)
I would take CAB's or Ron's code over mine anytime.
Very good point. Im keeping them both. Im currently at a MEP firm and they tend to only use integers. I'm normally in a civil design positions where CAB's routine would reign superior.
Good for you