Text Add/Substract lisp routine
Text Add/Substract lisp routine
(OP)
Hi,
Can anybody point me to a lisp routine that will add/substract an amount from a text line?
Thank you,
Roberttx.
Can anybody point me to a lisp routine that will add/substract an amount from a text line?
Thank you,
Roberttx.





RE: Text Add/Substract lisp routine
You can be more explicit?
And you can give an example me to have it more clear?. And thus to be able to help him
RE: Text Add/Substract lisp routine
RE: Text Add/Substract lisp routine
I have a series of text labels with a content similar to:
Elev. 2548.52
I need to be able to add or substract a certain quantity (provided by the user) to this (or other) labels.
I figured out it has to get each entity's values, modify (numerically) and then update (or create) a label similar to the old one.
Thank you,
Roberttx
RE: Text Add/Substract lisp routine
Assuming that each of your elevation text markers will ALL start with "ELEV. " and then contain a number, I have written the code below to do what I think you want. If you type in a positive number, it will add it to the existing number, if you type in a negative e.g. -25.50, it will subtract it from the original number and change your text to the new value. Let me know if this doesn't work the way that you want it to.
(defun c:ELCH ()
(setq OLDTX (entsel "\nPick TEXT to change: "))
(setq OLDDATA (entget (car OLDTX)))
(setq OLDCD1 (cdr (assoc 1 OLDDATA)))
(setq OLDEL (atof (substr OLDCD1 7)))
(setq NEWAD (getreal "\nType in NUMBER to add (- to subtract): "))
(setq NEWEL (+ OLDEL NEWAD))
(setq NEWTX (strcat "ELEV. "(rtos NEWEL)))
(setq EL (subst (cons 1 NEWTX) (assoc 1 OLDDATA) OLDDATA))
(entmod EL)
(princ)
);ends defun
Hope this helps,
Paul
RE: Text Add/Substract lisp routine
Roberttx.
RE: Text Add/Substract lisp routine
If it is any help, this LISP program can be edited so that it will ask you for the number to add/subtract, and then allow you to start selecting as many labels as you want and it will change the label elevations by that amount.
If you want that option, let me know, and I'll try to "make it so".
Paul
RE: Text Add/Substract lisp routine
As a matter of fact, your program has been very helpful. I refined it a little bit, by changing the number to 2 decimals and making a loop for changing every number on the way of the cursor.
Thanks again,
Roberto.