Add/Subtract numbers in texts

Add/Subtract numbers in texts

oli-123
Contributor Contributor
17,047 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)
17,048 Views
54 Replies
Replies (54)
Message 21 of 55

john.uhden
Mentor
Mentor
So is it '(0 . " MULTILEADER") or '(0 . "MLEADER") or maybe '(0 .
"M*LEADER")?

I would like to know for selection set filtering purposes.

John F. Uhden

0 Likes
Message 22 of 55

cadffm
Consultant
Consultant

DXF 0 is MULTILEADER, "MLEADER" is a fault in the help

Sebastian

0 Likes
Message 23 of 55

jallen_cph
Contributor
Contributor

John, here is what I get:

 

(entget (car (entsel)))
Select object: ((-1 . <Entity name: 2adc490fe30>) (0 . "MULTILEADER") (330 . <Entity name: 2ad4a122820>) (5 . "50BD3") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "P-DIM") (100 . "AcDbMLeader") (270 . 2) (300 . "CONTEXT_DATA{") (40 . 1.0) (10 15888.6 9641.22 0.0) (41 . 0.18) (140 . 0.18) (145 . 0.09) (174 . 1) (175 . 6) (176 . 0) (177 . 0) (290 . 1) (304 . "asdlkjasd") (11 0.0 0.0 1.0) (340 . <Entity name: 2ad4a118c00>) (12 15888.7 9641.34 0.0) (13 1.0 0.0 0.0) (42 . 0.0) (43 . 0.0) (44 . 0.0) (45 . 1.0) (170 . 1) (90 . -1073741824) (171 . 1) (172 . 5) (91 . -1073741824) (141 . 0.0) (92 . 0) (291 . 0) (292 . 0) (173 . 0) (293 . 0) (142 . 0.0) (143 . 0.0) (294 . 0) (295 . 0) (296 . 0) (110 15885.7 9638.75 0.0) (111 1.0 0.0 0.0) (112 0.0 1.0 0.0) (297 . 0) (302 . "LEADER{") (290 . 1) (291 . 1) (10 15888.2 9641.22 0.0) (11 1.0 0.0 0.0) (90 . 0) (40 . 0.36) (304 . "LEADER_LINE{") (10 15885.7 9638.75 0.0) (91 . 0) (170 . 1) (92 . -1056964608) (340 . <Entity name: 0>) (171 . -2) (40 . 0.0) (341 . <Entity name: 0>) (93 . 0) (305 . "}") (271 . 0) (303 . "}") (272 . 9) (273 . 9) (301 . "}") (340 . <Entity name: 2ad4a11bd70>) (90 . 279552) (170 . 1) (91 . -1056964608) (341 . <Entity name: 2ad4a114910>) (171 . -2) (290 . 1) (291 . 1) (41 . 0.36) (42 . 0.18) (172 . 2) (343 . <Entity name: 2ad4a118c00>) (173 . 1) (95 . 6) (174 . 1) (175 . 0) (92 . -1056964608) (292 . 0) (93 . -1056964608) (10 1.0 1.0 1.0) (43 . 0.0) (176 . 0) (293 . 0) (294 . 0) (178 . 0) (179 . 1) (45 . 1.0) (271 . 0) (272 . 9) (273 . 9) (295 . 1))

0 Likes
Message 24 of 55

SeeMSixty7
Advisor
Advisor

Here you go @john.uhden 

 

(0 . "MULTILEADER")

Entire Entget is (After I started indenting soon regretted it LOL)

((-1 . <Entity name: 1b562e6cb10>)
(0 . "MULTILEADER")
(330 . <Entity name: 1b519947820>)
(5 . "431") (100 . "AcDbEntity")
(67 . 0)
(410 . "Model")
(8 . "F.S. & Cut Width Dim")
(100 . "AcDbMLeader")
(270 . 2)
(300 . "CONTEXT_DATA{")
(40 . 1.0)
(10 4.36271e+06 -897070.0 0.0)
(41 . 0.18)
(140 . 0.18)
(145 . 0.09)
(174 . 1)
(175 . 6)
(176 . 0)
(177 . 0)
(290 . 1)
(304 . "asdasdas")
(11 0.0 0.0 1.0)
(340 . <Entity name: 1b519947a60>)
(12 4.36271e+06 -897070.0 0.0)
(13 1.0 0.0 0.0)
(42 . 0.0)
(43 . 0.0)
(44 . 0.0)
(45 . 1.0)
(170 . 1)
(90 . -1073741824)
(171 . 1)
(172 . 5)
(91 . -1073741824)
(141 . 0.0)
(92 . 0)
(291 . 0)
(292 . 0)
(173 . 0)
(293 . 0)
(142 . 0.0)
(143 . 0.0)
(294 . 0)
(295 . 0)
(296 . 0)
(110 4.36158e+06 -897070.0 0.0)
(111 1.0 0.0 0.0)
(112 0.0 1.0 0.0)
(297 . 0)
(302 . "LEADER{")
(290 . 1)
(291 . 1)
(10 4.36271e+06 -897070.0 0.0)
(11 1.0 0.0 0.0)
(90 . 0)
(40 . 0.36)
(304 . "LEADER_LINE{")
(10 4.36158e+06 -897070.0 0.0)
(91 . 0)
(170 . 1)
(92 . -1056964608)
(340 . <Entity name: 0>)
(171 . -2)
(40 . 0.0)
(341 . <Entity name: 0>)
(93 . 0)
(305 . "}")
(271 . 0)
(303 . "}")
(272 . 9)
(273 . 9)
(301 . "}")
(340 . <Entity name: 1b561407cd0>)
(90 . 279552)
(170 . 1)
(91 . -1056964608)
(341 . <Entity name: 1b519947a90>)
(171 . -2)
(290 . 1)
(291 . 1)
(41 . 0.36)
(42 . 0.18)
(172 . 2)
(343 . <Entity name: 1b519947a60>)
(173 . 1)
(95 . 6)
(174 . 1)
(175 . 0)
(92 . -1056964608)
(292 . 0)
(93 . -1056964608)
(10 1.0 1.0 1.0)
(43 . 0.0)
(176 . 0)
(293 . 0)
(294 . 0)
(178 . 0)
(179 . 1)
(45 . 1.0)
(271 . 0)
(272 . 9)
(273 . 9)
(295 . 1)
)
0 Likes
Message 25 of 55

john.uhden
Mentor
Mentor
To ward off faults it seems like '(0 . "M*LEADER") would be a safe bet.

John F. Uhden

0 Likes
Message 26 of 55

john.uhden
Mentor
Mentor

Okay.  That was easy (I think).

See if the new attached version works on MLeaders (I haven't tested).

John F. Uhden

Message 27 of 55

jallen_cph
Contributor
Contributor

John,

 

I tried your revised version and it is still filtering mleaders from the selection. I tried all selection modes as well. 

I also tried replacing all instances of "M*Leader" in the code with both "MLeader" and "Multileader" but there was no change. 

0 Likes
Message 28 of 55

johnyDFFXO
Advocate
Advocate

The issue is the content code. It's 304 instead of 1.

 

         '(
            (-4 . "<OR")
              (-4 . "<AND")(0 . "MTEXT,TEXT") (1 . "*#*") (-4 . "AND>")
	      (-4 . "<AND")(0 . "MULTILEADER") (304 . "*#*") (-4 . "AND>")
              (-4 . "<AND")(0 . "INSERT")(66 . 1)(-4 . "AND>")
            (-4 . "OR>")
          )
0 Likes
Message 29 of 55

cadffm
Consultant
Consultant

It will work for Mtext-Mleaders if you change this one line:

 

change
(-4 . "<AND")(0 . "MTEXT,M*LEADER,TEXT")(1 . "*#*")(-4 . "AND>")

 

to
(-4 . "<AND")(0 . "MTEXT,TEXT")(1 . "*#*")(-4 . "AND>")
(-4 . "<AND")(0 . "MULTILEADER")(304 . "*#*")(-4 . "AND>")

 

But note  there are three kinds of mleaders..

MTEXT - Editnum will work with the little edit above

BLOCK - There are text informations possible(acts like Attributes ), EditNum will not work

(the textstring stores in on eor more DXF 302 dottedpairs and the vla-object has no property TestString, thats why the |filter will not working and also the re-write data would not works)

and

None (without text data, no text data = no editnum required)

Sebastian

0 Likes
Message 30 of 55

jallen_cph
Contributor
Contributor

That did the trick! Thank you all so so much!

0 Likes
Message 31 of 55

john.uhden
Mentor
Mentor
First:
Make sure I put commas between each entity type in
(setq ...
|filter
'(
(-4 . " (-4 . ""AND>")
(-4 . "")
(-4 . "OR>")
)
)

Second:
It will ignore (exclude) text without any numbers.

John F. Uhden

0 Likes
Message 32 of 55

john.uhden
Mentor
Mentor

Hi, Sebastian.

I hadn't noticed the 304.  It's sorta like dealing with Land Desktop (RIP) points where there is a 302 code for raw description and a 303 code for "processed" descriptions.

I thought I had accounted for attributes.  I have not yet accounted for subjunctives.

I will still try to fix EDITNUM because it has the ability to change numbers on multiple lines of Mtext (or similar) thingies.  AND huge numbers.  Hey, I may need it some day when I grow up to these modren releases.  Seriously though, I hope I am dead before I grow up.

John F. Uhden

0 Likes
Message 33 of 55

Anonymous
Not applicable

Thanks for posting this. Very helpful!! Got the Mleader 1 to work after taking your 10/2/19 revision and applying that minor alteration left 2-4 posts up.

 

Seems to not work in instances where the text has multiple numbers right next to each other separated by a dash, but for editing elevation callouts overall this is extremely helpful!!

0 Likes
Message 34 of 55

cadffm
Consultant
Consultant

@Anonymous  schrieb:

Seems to not work in instances where the text has multiple numbers right next to each other separated by a dash


I'm sure John would like an example(DWG), but the example should be a TEXT or MTEXT and not a MLEADER,
DWG format 2000 or 2004.

Sebastian

0 Likes
Message 35 of 55

Anonymous
Not applicable

I would like to highlight though, that this LISP is amazing an it really should be up to the user applying it to filter out objects that are not intended to be adjusted which is probably better practice rather than just highlighting everything and assuming everything will be fine. 🙂

 

Here is my test file. I don't know that I would ever expect to even run into this scenario, but I hope this helps in your development of this tool.

 

Using EDITNUM to add 3 - seems like for all text, mtext, and mleaders that it replaces "test123-123" with just "test126" when I was expecting to get "test126-126".

 

0 Likes
Message 36 of 55

john.uhden
Mentor
Mentor
I think the internal notes say that it will work on only one number per
line of text (for Mtext that would be a new line for each hard return (\\P)
or soft return (\\n).
It was intended to change multiple grade labels in one shot Where I come
from (NJ, USA) we are always labelling curb and gutter elevations in the
format:
TC 43.43
G 42.93
With this program it doesn't matter whether each label is one piece of Text
or multiple lines of Mtext. From what I've seen, the more experienced
AutoCAD draftspeople prefer Mtext whereas the less experienced prefer the
simplicity of Text. Admittedly, the Text Editor is easier and faster than
the Mtext editor.
Anyway, I'm glad you have found it helpful. It is sort of a Godsend when
someone changes the datum near the end of a project.

John F. Uhden

Message 37 of 55

Anonymous
Not applicable

Hello John

 

How about subtracting the last 5 digits of the name like - 2000.

 

Sample:   125A VP A-D3F05-651404-0001 COP 1FL+14620 

Into :  125A VP A-D3F05-651404-0001 COP 1FL+12620 

 

Please Help. I want to edit all the name by subtracting the elevation.

Thank you in advance.

0 Likes
Message 38 of 55

john.uhden
Mentor
Mentor

This is not as sophisticated as EDITNUM, but here's the start...

(defun c:SubtractName ( / old num prefix suffix new)
  (setq old (getstring "\nEnter old name: "))
  (setq amount (getint "\nAmount to change last five digits (integer): "))
  (setq prefix (substr old 1 (- (strlen old) 5)))
  (setq suffix (substr old (- (strlen old) 4)))
  (setq new (strcat prefix (itoa (+ (read suffix) amount)))))
  (princ new)
  (princ)
)
(defun c:SN ()(c:SubtractName))

For example:

Command: sn

Enter old name: abc__889_12599

Amount to change last five digits (integer): -2000
"abc__889_10599"

 

We just have to add the method of entity selection (hopefully just text), and processing.

John F. Uhden

0 Likes
Message 39 of 55

devitg
Advisor
Advisor

  Hi @john.uhden . please apologize  me for using your START . 

 

 

;; By JOHN.UHDEN 
(DEFUN C:SUBTRACTNAME  (/ AMOUNT OLD-DATA OLDNAME OLD NUM PREFIX SUFFIX NEW)
  (SETQ OLDNAME (SSNAME (SSGET "_:S+." '((0 . "*text"))) 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
  (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))

I learn a new one (read SUFFIX) instead (atoi suffix)

 

 

 

0 Likes
Message 40 of 55

john.uhden
Mentor
Mentor
Whaddya mean? I am honored and hoped that somebody would finish it.
Actually, it should ask for the old prefix and find all text objects
matching (strcat prefix "#####"). Please fix!

John F. Uhden

0 Likes