Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IDS on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text Add/Substract lisp routine

Status
Not open for further replies.

roberttx

Civil/Environmental
Aug 30, 2002
73
Hi,

Can anybody point me to a lisp routine that will add/substract an amount from a text line?

Thank you,

Roberttx.
 
Replies continue below

Recommended for you

Hi...

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
 
I have one that works on regular text (not mtext), and if the text line begins with a number. Email me at cabATeeiteamDOTcom if interested.
 
Hi,

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
 
Hi roberttx,

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
 
Thanks, Paul! This will save my life for a few strokes less on the calculator.

Roberttx.
 
Hey Roberttx,
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
 
Hi, Paul:

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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor