Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Add/Subtract numbers in texts

48 REPLIES 48
SOLVED
Reply
Message 1 of 49
oli-123
12426 Views, 48 Replies

Add/Subtract numbers in texts

I have a lot of texts that need to be modified like this one: TC=50.12

Is it possible to input a number to add/subtract the value in that text?

 

I know there are other threads with similar discussion like this one, but it doesn't apply to this particular problem I'm having.

 

Thanks!

48 REPLIES 48
Message 41 of 49
john.uhden
in reply to: devitg

(read) can come in handy in some odd situations.  F;rinstance if you want to allow entry of either a real or an integer but have to know which it is...

(setq number (getstring "\nNumber: "))
(setq number (read number))
(cond
  ((= (type number) 'REAL)(do_this))
  ((= (type number) 'INT)(do_that))
  (1 (do_other))
)

John F. Uhden

Message 42 of 49
devitg
in reply to: john.uhden

@john.uhden .

 

to check for 5 digit numbers. 

 

;; By JOHN.UHDEN 

(DEFUN C:SUBTRACTNAME  (/ AMOUNT OLD-DATA OLDNAME OLD NUM PREFIX SUFFIX NEW)
  (SETQ OLDNAME (SSNAME (SSGET "_:S+." '((0 . "*text") (1 . "*#####"))) 0))
  (SETQ OLD (CDR (ASSOC 1 (ENTGET OLDNAME))))
 ;(setq old (getstring "\nEnter old name: "))

 ;(setq amount (getint "\nAmount to change last five digits (integer): "))
  (SETQ AMOUNT -2000)
  (SETQ PREFIX (SUBSTR OLD 1 (- (STRLEN OLD) 5)))
  (SETQ SUFFIX (SUBSTR OLD (- (STRLEN OLD) 4))) ; string
  (atoi SUFFIX )
  (SETQ NEW (STRCAT PREFIX (ITOA (+ (READ SUFFIX) AMOUNT))))
  (PRINC NEW)
  (SETQ OLD-DATA (ENTGET OLDNAME))
  (SETQ OLD-DATA (SUBST (CONS 1 NEW) (ASSOC 1 OLD-DATA) OLD-DATA))
  (ENTMOD OLD-DATA)
  (PRINC)
  )
(DEFUN C:SN () (C:SUBTRACTNAME))

Message 43 of 49
Anonymous
in reply to: devitg

@john.uhden
@devitg

 

You are all good with this. I'm sorry because I am new to this Autocad Feature.

Thank's a lot for your help. I will continue studying this code because what I wanna do is change all the last 5 digits of all the names/Elevation on the drawing. 

 

Message 44 of 49
john.uhden
in reply to: Anonymous

"the last 5 digits of elevation?"  What, are you surveying Mount Everest?

John F. Uhden

Message 45 of 49
devitg
in reply to: Anonymous

@Anonymous  please upload a sample.dwg 

 

@john.uhden   elevation maybe   inches 

 

 

Message 46 of 49
john.uhden
in reply to: devitg

Well 15000 inches is 1250 feet, which is up there a ways. And 2000 inches is 166 feet, which is quite an adjustment.

"Old surveyors never die.  They just lose their bearings."  - Uhden

John F. Uhden

Message 47 of 49
Anonymous
in reply to: devitg

Hello devitg,

 

I have attach the sample DWG.

I appreciate  your effort about this LISP.

 

Message 48 of 49
Anonymous
in reply to: john.uhden

Thank you john,

 

I have attach the files for your reference.

Message 49 of 49
JohnC_ISM
in reply to: john.uhden

i just did an entire topo and didnt realize i didnt change the datum and this lisp just save me a days worth of work. holy crap thanks haha

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report