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

Add/Subtract numbers in texts

52 REPLIES 52
SOLVED
Reply
Message 1 of 53
oli-123
12802 Views, 52 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!

52 REPLIES 52
Message 2 of 53
SeeMSixty7
in reply to: oli-123

If you know the prefix is always 2 chars and an Equal sign then you simply step through each text entity, get the value, apply substr, then convert the string to a float apply your add factor and then rebuild and update the text value.

 

Here is a piece to get you started. All that is left is to set up a system to step through  selection set instead of picking a single entity.

 

(defun c:quick()
(setq myaddvalue 2.4
mytextent (car (entsel "\nSelect Text String"))
mytextdata (entget mytextent)
mytextvalue (cdr (assoc 1 mytextdata))
mytextprefix (substr mytextvalue 1 3)
mytextnumber (substr mytextvalue 4 (1- (strlen mytextvalue)))
myoldvalue (assoc 1 mytextdata)
mynewvalue (cons 1 (strcat mytextprefix (rtos (+ (atof mytextnumber) myaddvalue) 2 4)))
myentdata (subst mynewvalue myoldvalue mytextdata)
)
(entmod myentdata)
)

 

Good luck

 

Message 3 of 53
ВeekeeCZ
in reply to: oli-123

Try THIS freeware routine by CAD Studio, it handles more than add/subtracting numbers within a text.

Message 4 of 53
john.uhden
in reply to: oli-123

I think I posted this not that long ago, but I don't know where it went, so here it is again.

 

EDITNUM.lsp (attached)

 

; Adjusts any imbedded numeric strings of a selection set of text entities.

; v2.4 (3-1-96) added (max ... (@prec $cv_diff)) in line 133
; v2.5 (3-4-96) changed @prec to @rprec for real and added @sprec for strings.
; v2.6 (12-11-99) added multiplcation option as requested by Jeremy Lange of
; Maser (Toms River); also added numeric text filter '(1 . "*#*")
; v15.00 (04-07-00) for R15
; (12-17-00) added multiple picks for Picklayer option
; v15.01 (09-05-02) added support for Inserts with Attributes
; v15.02 (01-09-03) revised to update attributes.
; v15.03 (02-24-04) revised to try and handle K&K's large number.
; v17.00 (03-03-09) revised to handle Mtext

 

 

John F. Uhden

Message 5 of 53
oli-123
in reply to: john.uhden

Thanks all! I wish I can learn some LISP, but I wish I have time for that. 😞

Message 6 of 53
wkmvrij
in reply to: oli-123

Now that is so shortsighted! As a rule, any time you spend on learning to code in Visual Lisp to solve small or big problems in your work is earned back in multiples. 

Message 7 of 53
john.uhden
in reply to: wkmvrij

Didn't you know?  Myopic people never have enough time to see things through.  :]

John F. Uhden

Message 8 of 53
pproestos
in reply to: john.uhden

thx @john.uhden you are a cad god...

Message 9 of 53
jallen_cph
in reply to: pproestos

Is there any way to make this (or something similar) work on Mleaders with MText? I have routines that will update regular text, mtext, mleaders with attibutes, attributed blocks...but none of them work on an mleader with mtext. 

 

I've got two sites that have a datum change and need to adjust all of the spot elevations by a constant amount. 

Message 10 of 53
devitg
in reply to: jallen_cph

please upload your-sample.dwg

 

Message 11 of 53
jallen_cph
in reply to: devitg

I can't upload the actual files due to client privileges but here is dwg with the mleader style in question. The goal is to adjust all of the spot shots in the design file by a constant amount, in this case -0.87.

 

For reference I'm running Civil3D 2019 but these are not Civil 3D projects. 

Message 12 of 53
john.uhden
in reply to: jallen_cph

The EDITNUM.lsp I posted I believe works on TEXT, MTEXT, and ATTRIBs.
I am ignorant as to whether MTEXT is a separate entity from an MLEADER.
Just try it out. It won't bite you.

It is especially good for datum changes because if one (1) Mtext has two
lines, like...
TC 120.54
G 120.01
It will adjust both numbers.

John F. Uhden

Message 13 of 53
jallen_cph
in reply to: john.uhden

John: I tried your lisp but it won't select an mleader for me, just says 0 found.

Message 14 of 53
john.uhden
in reply to: jallen_cph

Okay then. I'll try to crank up my C3D 2016 and see what an MLEADER is
made of and add that capability. Just don't expect it any time soon. My
computer "fun time" is strictly monitored. No, not by me. (Right now she
thinks I'm paying bills).

John F. Uhden

Message 15 of 53
devitg
in reply to: john.uhden

(setq value-to-add(getreal "\n State value to add "))
       
(VLAX-FOR MULTILEADER MULTILEADER-vl-ss
  (setq MULTILEADER-string (vla-Get-textString  MULTILEADER))
  (setq old-value(atoi MULTILEADER-string ))
(setq new-value (+ old-value value-to-add))
(setq new-string (rtos new-value 2 2))
 (VLA-PUT-TEXTSTRING MULTILEADER new-string)      
 )     
Message 16 of 53
john.uhden
in reply to: devitg

Thanks for saving me the research.

The slight difference my EDITNUM has is that it operates on all numeric values within a text string and can handle super large values (Keller & Kirkpatrick had a tax map numbering project that had like 20-place integers/reals).  Come to think of it, I think it maintains the precision unless the precision of the additive is greater than the precision of the existing (unless of course if the existing were to 1 place but the sum was to 2 places but with a trailing zero, in which case the 1 place would be honored).  I probably made like $1.23 per hour, but they were happy.  Anyway, that's infinitely more than any of us makes around this place.

There is no denying the gratitude, but gratitude doesn't pay any of my bills.

John F. Uhden

Message 17 of 53
john.uhden
in reply to: devitg

I checked out my code and it's easy to add MLEADERs.  Um, but what is an MLEADER's dxf 0 name?  What about its ObjectName?

John F. Uhden

Message 18 of 53
jallen_cph
in reply to: john.uhden

Thanks John, I do appreciate you taking the time to look into this.

 

The ObjectName is AcDbMLeader isn't it? As far as the DXF 0, I don't see that listed in the group codes for Mleaders. DXF 172 is content type, and 290 is listed as hasMtext. But, I really don't know what I'm looking at beyond some basic lisp writing lol.

Message 19 of 53
cadffm
in reply to: john.uhden

I gave Adesk feedback, Adesk had to fix MLEADER and use MULTILEADER in the DXF / LISP help.

 

AutoDesk help pages url:

http://help.autodesk.com/view/ACD/2020/ENU/

Productnames ACD/ACDLT/AMECHPP/ARCHDESK/CIV3D/...

Productversion 2015/2016/2017/2018/2019/2020/...

Productlanguage ENU/DEU/FRA/... (you can change the language also on the help page, in the upper right corner)

 

Samples

Programming section http://help.autodesk.com/view/OARX/2020/ENU/

DXF Reference

MLEADER MULTILEADER - DXF

Sebastian

Message 20 of 53
john.uhden
in reply to: jallen_cph

To see what the DXF code 0 is, do an (entget (car (entsel)))

John F. Uhden

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