Add/Subtract numbers in texts

Add/Subtract numbers in texts

oli-123
Contributor Contributor
16,918 Views
54 Replies
Message 1 of 55

Add/Subtract numbers in texts

oli-123
Contributor
Contributor

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!

0 Likes
Accepted solutions (1)
16,919 Views
54 Replies
Replies (54)
Message 2 of 55

SeeMSixty7
Advisor
Advisor

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

 

0 Likes
Message 3 of 55

ВeekeeCZ
Consultant
Consultant

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

Message 4 of 55

john.uhden
Mentor
Mentor
Accepted solution

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 55

oli-123
Contributor
Contributor

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

0 Likes
Message 6 of 55

wkmvrij
Advocate
Advocate

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 55

john.uhden
Mentor
Mentor

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

John F. Uhden

0 Likes
Message 8 of 55

pproestos
Collaborator
Collaborator

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

0 Likes
Message 9 of 55

jallen_cph
Contributor
Contributor

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. 

0 Likes
Message 10 of 55

devitg
Advisor
Advisor

please upload your-sample.dwg

 

0 Likes
Message 11 of 55

jallen_cph
Contributor
Contributor

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. 

0 Likes
Message 12 of 55

john.uhden
Mentor
Mentor
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

0 Likes
Message 13 of 55

jallen_cph
Contributor
Contributor

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

0 Likes
Message 14 of 55

john.uhden
Mentor
Mentor
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 55

devitg
Advisor
Advisor
(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)      
 )     
0 Likes
Message 16 of 55

john.uhden
Mentor
Mentor

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

0 Likes
Message 17 of 55

john.uhden
Mentor
Mentor

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

0 Likes
Message 18 of 55

jallen_cph
Contributor
Contributor

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.

0 Likes
Message 19 of 55

cadffm
Consultant
Consultant

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

0 Likes
Message 20 of 55

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

John F. Uhden

0 Likes