Lisp routine to add a specified number to a dtext or mtext number

demus72
Collaborator
Collaborator

Lisp routine to add a specified number to a dtext or mtext number

demus72
Collaborator
Collaborator

I have a set of plans for a water treatment plant. The plans show elevation information for many different levels, floor, wier, high water level, low water level, etc., of the plant. The original survey was on an older datum and we now have a new survey of the same plant on a new datum. In order to re-use the previous plans, I need to add a specific value to all the elevations shown. I could edit one at a time but there are many many elevations called out.

 

My question is, where could I find a lisp routine that prompts the user for a specific value to add, or subtract, to selected dtext or mtext numbers? It would be nice if I could enter the desired number to add or subtract then select the dtext or mtext to be modified.

 

I found a lsp routine written by user Commandobill on Cadtutor.net but it changed all my numbers to the number I entered to add.

 

(defun c:addn ( / ss)
(vl-load-com)
(if (and (setq ss (ssget "X" (list (cons 0 "*text"))))
(setq amt (getreal "\nPlease type the amount you would like to add: ")))
(progn
(mapcar '(lambda (z) (vla-put-textstring z (rtos (+ (atof (vla-get-textstring z)) amt) 2 3)))
(mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))))
)
)
(princ)
)
EvilSi

 

Maybe someone could edit this or has one of their own they would be willing to share?

 

Thanks!

0 Likes
Reply
4,397 Views
18 Replies
Replies (18)

Kent1Cooper
Consultant
Consultant

Do a little Searching.  I'm pretty sure exactly this request has come up before.  If around here, it's more likely to be in the Customization Forum than the version-related ones.  I'll leave you to experiment with exactly what terms to Search for.

Kent Cooper, AIA
0 Likes

ВeekeeCZ
Consultant
Consultant

Actually the very last week I've been testing a commenting THIS free complex routine by CadStudio for text-number editing. Works good 🙂

Thanks to @vladimir_michl for developing this.

 

Ranjit_Singh2
Advisor
Advisor

There are many routines out there. For something quick and dirty, use below. No error checking done.

 

(defun c:somefunc  (/ val val1)
  (setq val (getreal "\nEnter difference to add/subtract :"))
  (mapcar '(lambda (x)
             (and (not (listp x))
                  (setq entdata (entget x))
                  (not (= (type (setq val1 (read (cdr (assoc 1 entdata))))) 'sym))
                  (entmod (subst (cons 1 (rtos (+ val val1) 2 2)) (assoc 1 entdata) entdata))))
          (mapcar 'cadr (ssnamex (ssget '((0 . "TEXT,MTEXT"))))))
  (princ))
0 Likes

john.uhden
Mentor
Mentor

Try out my EDITNUM.LSP, attached as freeware with security removed.

I am pretty sure it handles Text, Mtext, and Attributes.

 

But be careful.  If you are using old-fashioned DCA/Softdesk point blocks, it will probably change the value of the Point Number attribute.  But I think that locking that attribute's layer will prevent that.  Testing is strongly recommended.  Just one Undo will put everything back the way it was.

 

 

John F. Uhden

pproestos
Collaborator
Collaborator

@john.uhden

It doesn't work well with negative numbers... especially when they

are as attribute block texts...

 

Instead with positive numbers is awesome...

0 Likes

john.uhden
Mentor
Mentor

I am aware of the problem.

The reason is that I had to rewrite it from simple terms to something much more complex to compensate for a client having numbers that were over 16 digits long, but also had digits after the decimal point.  There was never a need to deal with negative numbers.  But that's no excuse.  I will have to find some time to fix it.  Please be patient.

John F. Uhden

pproestos
Collaborator
Collaborator

That's ok even now your lisp helped me a lot to my job.

But if you can evolve it, it will be great! 🙂

 

 

0 Likes

john.uhden
Mentor
Mentor
I am all in favor of the origin of the species. 🙂

John F. Uhden

0 Likes

wes.sheffer
Contributor
Contributor

John,

Thanks a lot for sharing your Editnum routine.  What a useful tool.

I wonder if there's a simple way to get it to work on multileaders in which the Content is formatted as Mtext.  I have a grading plan on which the spot elevations are multileaders.  We'd like to raise about 90% of the site uniformly, and that means manually editing the text of roughly 300 multileaders to adjust the elevations by the same amount.

0 Likes

john.uhden
Mentor
Mentor
Now that I have a newer version of AutoCAD installed, I should add
multileaders to the selection capability.

John F. Uhden

e_elhussieny
Observer
Observer

GOOD ONE 

THANKS

0 Likes

andrew_pullinger
Explorer
Explorer

Hi John, great lisp and brilliant for changing level datums in surveys.

 

Only one problem issue we have experienced is say; +139.75 all the levels change to 2 decimal places, however +139.74 they revert to 156.68000000000001 instead of 156.68. The get around has been to do the transformation in to stages +139 and then +.074 and that works fine.

 

Any updates on a great lisp?

0 Likes

john.uhden
Mentor
Mentor

@andrew_pullinger 

That doesn't happen for me.

Are you running v.17.04?

It was written to apply the greater precision of the original vs. additive.

IOW 1.5 + 1.25 = 2.75

Maybe everyone would prefer it to use the lesser precision?

IOW 1.5 + 1.25 = 2.8

John F. Uhden

0 Likes

andrew_pullinger
Explorer
Explorer

Hi John, we had the v15.04 version. I have downloaded the link above again v17.00, and the same thing happens. I type a single line of AutoCAD text value 10.00, and if I add difference 139.75 to value it equals 149.75, but if I repeat and add difference 139.74 to value of 10.00 it equals 149.74000000000001, regardless to unit settings.

 

As previously mentioned, we resolved this, doing it in two parts 139.00, then 0.74, and we are grateful for you sharing such a brilliant lisp!

0 Likes

john.uhden
Mentor
Mentor

@andrew_pullinger 

Attached is EDITNUM v17.04.

I hope it behaves better for you than any previous version.  Of course you will let me know.

John F. Uhden

Sea-Haven
Mentor
Mentor

Another we have used this for years 

 

; Adds a fixed amount to a number


(Alert "TO USE JUST TYPE A2L or A2LM for multiple ")


;(setvar "cmdecho" 1)
(setq olddimzin (getvar "Dimzin"))
(setvar "dimzin" 0)

(DEFUN c:A2L ( / test en1 v1 a b el en1)
;(if (not AH:getvalsm)(load "Multi Getvals"))
;(setq v2 (Atof (nth 0 (AH:getvalsm (list "Add to levels" "Enter amount" 5 4 "1")))))
(setq v2 (getreal "\nEnter difference to use "))

(setq test 1)
(while (= test 1)
      (setq en1 (car (entsel "\nSelect text number:" )))
       (if (/= en1 nil)
        (progn
        (setq el1 (entget en1))
        (setq v1 (atof (cdr (assoc 1 el1))))
        (setq a (+ v1 v2))
        (setq b (rtos a 2 3))
        (setq el (subst (cons 1 b) (assoc 1 el1) el1))
        (entmod el)
;        (entupd en1)
        );progn
       (princ "\nplease pick again"); else
     );if
); while true
(setq el nil)
(setq en nil)
(setq a nil)
(setq v1 nil)

(setvar "cmdecho" 1)
(setvar "dimzin" olddimzin)
(princ)
); END a2l DEFUN

(defun c:A2LM ()
;(if (not AH:getvalsm)(load "Multi Getvals"))
;(setq v2 (Atof (nth 0 (AH:getvalsm (list "Add to levels" "Enter amount" 5 4 "1")))))

(setq v2 (getreal "\nEnter difference to use "))
(setq ss (ssget (list (cons 0 "*Text"))))
(setq len (sslength ss))
(setq x 0)

(repeat len
(setq en1 (ssname ss x))
        (setq el1 (entget en1))
        (setq v1 (atof (cdr (assoc 1 el1))))
        (setq a (+ v1 v2))
        (setq b (rtos a 2 3))
        (setq el (subst (cons 1 b) (assoc 1 el1) el1))
        (entmod el)
(setq x (+ x 1))
); repeat

(setq el nil
      ss nil)
(setq en nil)
(setq a nil)
(setq v1 nil)


(setvar "dimzin" olddimzin)
(setvar "cmdecho" 1)
(princ)

); END a2lm DEFUN
0 Likes

idigg-be
Enthusiast
Enthusiast

@john.uhden wrote:

@andrew_pullinger 

Attached is EDITNUM v17.04.

I hope it behaves better for you than any previous version.  Of course you will let me know.



Great Lisp, worked the way i expected for mtxt, but it filters out all of my multileaders.  

0 Likes

john.uhden
Mentor
Mentor

@idigg-be ,

Thank you for the compliment.

I won't remember how it works until I open it and slog into the quagmire.

But if it works on Mtext, I must be able to make it work on Mleaders.

I'll see what I can do.

John F. Uhden

0 Likes