Jump to content
VisDak

numeric text editing (add or subtracting)

Recommended Posts

VisDak

Hi all,

 

Good day, i have a drawing that all levels of services are indicated, only i have now a problem regarding by revising the levels of annotation, i have to add it by 200mm, of all the levels :cry: and all levels will be edit and maybe i'll be missed some of it,

 

if a route cud sellect all or selected the text and choose add or subtract then put the valve to be merge(add or subtract) on numeric annotation, and it will be easier and safe, please see image for other clarifications

 

many thanks,

text editing1.jpg

text editing2.jpg

Share this post


Link to post
Share on other sites
Lee Mac

Try this VisDak:

 

(defun c:Text_Inc (/ *error* ParseNumbers uFlag ss)
 (vl-load-com)
 ;; Lee Mac  ~  10.03.10

 (defun *error* (msg)
   (setvar 'NOMUTT 0)
   (and uFlag (vla-EndUndoMark *doc))
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error: " msg " **")))
   (princ))
 

 (defun ParseNumbers (str / lst Num Aph x rtn)
   ;; Lee Mac  ~  20.09.09
   (setq lst (vl-string->list str) Num "" Aph "")
   
   (while (setq x (car lst))
     (setq lst (cdr lst))
     
     (cond (  (and (/= "" Num) (= 46 x))
              (setq Num (strcat Num (chr x))))
           
           (  (< 47 x 58)
              (setq Num (strcat Num (chr x))
                    rtn (cons Aph rtn) Aph ""))
           
           (t (setq Aph (strcat Aph (chr x))
                    rtn (cons (read Num) rtn) Num ""))))
   
   (vl-remove nil
     (vl-remove "" (reverse (cons Aph (cons (read Num) rtn))))))
 

 (setq *inc* (cond (*inc*) (1.0)))
 (setq *inc* (cond ((getreal (strcat "\nSpecify Increment <"
                                     (vl-princ-to-string *inc*) "> : ")))
                   (*inc*)))

 (setq *doc (cond (*doc) ((vla-get-ActiveDocument (vlax-get-acad-object)))))

 (setvar 'NOMUTT 1)
 (princ "\nSelect Text to Increment <All> : ")
 (if (or (ssget "_:L" '((0 . "MTEXT,TEXT")))
         (ssget "_X"  '((0 . "MTEXT,TEXT"))))
   (progn
     (setq uFlag (not (vla-StartUndoMark *doc)))
     
     (vlax-for obj (setq ss (vla-get-ActiveSelectionSet *doc))
       (vla-put-TextString obj
         (apply (function strcat)
                (mapcar
                  (function
                    (lambda (x) (if (vl-position (type x) '(INT REAL))
                                  (vl-princ-to-string (+ x *inc*)) x)))

                  (ParseNumbers (vla-get-TextString obj))))))

     (vla-delete ss)
     (setq uFlag (vla-EndUndoMark *doc))))  

 (setvar 'NOMUTT 0)
 (princ))
 

Alternatively, I think CAB wrote a good once a while back here.

 

Lee

Share this post


Link to post
Share on other sites
squowse

thanks a million for this, saved me a couple of hours work changing levels on a survey drawing to suit a new datum.

i was particularly impressed how it found numbers in mixed text and numeric text entities.

 

for Autocad 2010 users (and 2008 onwards i think) add the line

 

(vl-load-com)

 

somewhere near the start.

 

thanks again

 

for google search - autocad autolisp utility program tool to add or subtract from numeric text numbers.

Share this post


Link to post
Share on other sites
Lee Mac
thanks a million for this, saved me a couple of hours work changing levels on a survey drawing to suit a new datum.

i was particularly impressed how it found numbers in mixed text and numeric text entities.

 

Thanks squowse, I'm glad you like it :) I'm yet to hear from VisDak...

 

for Autocad 2010 users (and 2008 onwards i think) add the line

 

(vl-load-com)

 

somewhere near the start.

 

Oh yes, that should be there (I normally have that in my ACADDOC.lsp, so don't realise when it is missing). I have updated the above code.

Share this post


Link to post
Share on other sites
VisDak

Thanks Lee Mac,

 

:D

Share this post


Link to post
Share on other sites
Lee Mac

You're welcome VisDak :)

Share this post


Link to post
Share on other sites
Joebris

That code has worked perfectly for me Lee. Thanks.

 

Now unfortunately, I need to do something similar to another survey but on this one the text I need to change is part of a block (containing TEXT and a point). Do you have version that would work with this?

 

Many thanks

Share this post


Link to post
Share on other sites
squowse

Try exploding one of the blocks. If the text is an "attribute" of the block then it will disappear after exploding or change to zero..

This will then be more difficult. If the not then the text can be updated after exploding you could use right-click>select similar to select all the blocks for exploding.

Share this post


Link to post
Share on other sites
Lee Mac

Try the following version:

 

[color=GREEN];; Text Increment  -  Lee Mac[/color]
[color=GREEN];; Increments numerical data found in a selected Text, MText or Attribute object[/color]
[color=GREEN];; by a value specified by the user.[/color]

([color=BLUE]defun[/color] c:txtinc ( [color=BLUE]/[/color] e i l )
   ([color=BLUE]if[/color] ([color=BLUE]null[/color] *inc*)
       ([color=BLUE]setq[/color] *inc* 1.0)
   )
   ([color=BLUE]if[/color] ([color=BLUE]setq[/color] i ([color=BLUE]getreal[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\nSpecify Increment <"[/color] ([color=BLUE]rtos[/color] *inc* 2) [color=MAROON]">: "[/color])))
       ([color=BLUE]setq[/color] *inc* i)
   )
   ([color=BLUE]if[/color] ([color=BLUE]equal[/color] 0.0 ([color=BLUE]rem[/color] *inc* 1) 1e-
       ([color=BLUE]setq[/color] *inc* ([color=BLUE]fix[/color] *inc*))
   )
   ([color=BLUE]while[/color]
       ([color=BLUE]progn[/color] ([color=BLUE]setvar[/color] 'errno 0) ([color=BLUE]setq[/color] e ([color=BLUE]car[/color] ([color=BLUE]nentsel[/color] [color=MAROON]"\nSelect Text, MText or Attribute: "[/color])))
           ([color=BLUE]cond[/color]
               (   ([color=BLUE]=[/color] 7 ([color=BLUE]getvar[/color] 'errno))
                   ([color=BLUE]princ[/color] [color=MAROON]"\nMissed, try again."[/color])
               )
               (   ([color=BLUE]=[/color] 'ename ([color=BLUE]type[/color] e))
                   ([color=BLUE]if[/color] ([color=BLUE]wcmatch[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 0 ([color=BLUE]setq[/color] e ([color=BLUE]entget[/color] e)))) [color=MAROON]"*TEXT,ATTRIB"[/color])
                       ([color=BLUE]if[/color] ([color=BLUE]vl-some[/color] '[color=BLUE]numberp[/color] ([color=BLUE]setq[/color] l (LM:SplitString ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 1 e)))))
                           ([color=BLUE]entmod[/color]
                               ([color=BLUE]subst[/color]
                                   ([color=BLUE]cons[/color] 1
                                       ([color=BLUE]apply[/color] '[color=BLUE]strcat[/color]
                                           ([color=BLUE]mapcar[/color]
                                               ([color=BLUE]function[/color]
                                                   ([color=BLUE]lambda[/color] ( x )
                                                       ([color=BLUE]if[/color] ([color=BLUE]and[/color] ([color=BLUE]=[/color] 'int ([color=BLUE]type[/color] x)) ([color=BLUE]=[/color] 'int ([color=BLUE]type[/color] *inc*)))
                                                           ([color=BLUE]itoa[/color] ([color=BLUE]+[/color] x *inc*))
                                                           ([color=BLUE]if[/color] ([color=BLUE]member[/color] ([color=BLUE]type[/color] x) '(int real))
                                                               ([color=BLUE]rtos[/color] ([color=BLUE]+[/color] x *inc*) 2)
                                                               x
                                                           )
                                                       )
                                                   )
                                               )
                                               l
                                           )
                                       )
                                   )
                                   ([color=BLUE]assoc[/color] 1 e) e
                               )
                           )
                           ([color=BLUE]princ[/color] [color=MAROON]"\nText contains no numerical data."[/color])
                       )
                       ([color=BLUE]princ[/color] [color=MAROON]"\nInvalid object selected."[/color])
                   )
               )
           )
       )
   )
   ([color=BLUE]princ[/color])
)            

[color=GREEN];; Split String  -  Lee Mac[/color]
[color=GREEN];; Splits a string into a list of text and numbers[/color]

([color=BLUE]defun[/color] LM:SplitString ( s )
   (
       ([color=BLUE]lambda[/color] ( l )
           ([color=BLUE]read[/color]
               ([color=BLUE]strcat[/color] [color=MAROON]"("[/color]
                   ([color=BLUE]vl-list->string[/color]
                       ([color=BLUE]apply[/color] '[color=BLUE]append[/color]
                           ([color=BLUE]mapcar[/color]
                               ([color=BLUE]function[/color]
                                   ([color=BLUE]lambda[/color] ( a b c )
                                       ([color=BLUE]if[/color]
                                           ([color=BLUE]or[/color]
                                               ([color=BLUE]<[/color] 47 b 58)
                                               ([color=BLUE]and[/color] ([color=BLUE]=[/color] 45 b) ([color=BLUE]<[/color] 47 c 58) ([color=BLUE]not[/color] ([color=BLUE]<[/color] 47 a 58)))
                                               ([color=BLUE]and[/color] ([color=BLUE]=[/color] 46 b) ([color=BLUE]<[/color] 47 a 58) ([color=BLUE]<[/color] 47 c 58))
                                           )
                                           ([color=BLUE]list[/color] b)
                                           ([color=BLUE]list[/color] 32 34 b 34 32) 
                                       )
                                   )
                               )
                               ([color=BLUE]cons[/color] [color=BLUE]nil[/color] l) l ([color=BLUE]append[/color] ([color=BLUE]cdr[/color] l) ([color=BLUE]list[/color] [color=BLUE]nil[/color]))
                           )
                       )
                   )
                   [color=MAROON]")"[/color]
               )
           )
       )
       ([color=BLUE]vl-string->list[/color] s)
   )
)

([color=BLUE]princ[/color])

Share this post


Link to post
Share on other sites
Joebris

Thanks Lee, that works really well for adding/subtracting a number to an attribute. Is there a way to make it do it to all of the blocks in the drawing like Text_Inc above, rather than having to click each one individually? (I have hundreds in my drawing).

Share this post


Link to post
Share on other sites
Lee Mac
...that works really well for adding/subtracting a number to an attribute.

 

In your original post you specifically stated that you needed to change TEXT within a block, not an attribute:

 

...the text I need to change is part of a block (containing TEXT and a point)

 

Hence, upon selecting a Text object nested within a block reference, the above program will alter the value of that Text object within the block definition referenced by the selected block reference, subsequently updating the value of the Text for all references of the block in the drawing (following a regen).

 

Is there a way to make it do it to all of the blocks in the drawing like Text_Inc above, rather than having to click each one individually? (I have hundreds in my drawing).

 

For attribute modification, a window selection is certainly possible, however, if the selected block references contain more than one attribute, the program would need to know which attribute is to be modified in each attributed block reference.

 

However, I cannot justify the voluntary time required for this modification, but would be willing to provide a quotation to customise the program to suit your requirements; if you are interested, contact me through my site.

Share this post


Link to post
Share on other sites
ABUSAIF

Lee Mac, this lisp is great, Thank you, how can I control the precision in the final number is there a way to add ' or " to the end , example 17.0 I want it 17.00'. I really appreciat your help.

 

Thanks

Share this post


Link to post
Share on other sites
Cylis0509
Try this VisDak:

 

(defun c:Text_Inc (/ *error* ParseNumbers uFlag ss)
 (vl-load-com)
 ;; Lee Mac  ~  10.03.10

 (defun *error* (msg)
   (setvar 'NOMUTT 0)
   (and uFlag (vla-EndUndoMark *doc))
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error: " msg " **")))
   (princ))
 

 (defun ParseNumbers (str / lst Num Aph x rtn)
   ;; Lee Mac  ~  20.09.09
   (setq lst (vl-string->list str) Num "" Aph "")
   
   (while (setq x (car lst))
     (setq lst (cdr lst))
     
     (cond (  (and (/= "" Num) (= 46 x))
              (setq Num (strcat Num (chr x))))
           
           (  (< 47 x 58)
              (setq Num (strcat Num (chr x))
                    rtn (cons Aph rtn) Aph ""))
           
           (t (setq Aph (strcat Aph (chr x))
                    rtn (cons (read Num) rtn) Num ""))))
   
   (vl-remove nil
     (vl-remove "" (reverse (cons Aph (cons (read Num) rtn))))))
 

 (setq *inc* (cond (*inc*) (1.0)))
 (setq *inc* (cond ((getreal (strcat "\nSpecify Increment <"
                                     (vl-princ-to-string *inc*) "> : ")))
                   (*inc*)))

 (setq *doc (cond (*doc) ((vla-get-ActiveDocument (vlax-get-acad-object)))))

 (setvar 'NOMUTT 1)
 (princ "\nSelect Text to Increment <All> : ")
 (if (or (ssget "_:L" '((0 . "MTEXT,TEXT")))
         (ssget "_X"  '((0 . "MTEXT,TEXT"))))
   (progn
     (setq uFlag (not (vla-StartUndoMark *doc)))
     
     (vlax-for obj (setq ss (vla-get-ActiveSelectionSet *doc))
       (vla-put-TextString obj
         (apply (function strcat)
                (mapcar
                  (function
                    (lambda (x) (if (vl-position (type x) '(INT REAL))
                                  (vl-princ-to-string (+ x *inc*)) x)))

                  (ParseNumbers (vla-get-TextString obj))))))

     (vla-delete ss)
     (setq uFlag (vla-EndUndoMark *doc))))  

 (setvar 'NOMUTT 0)
 (princ))
 

Alternatively, I think CAB wrote a good once a while back here.

 

Lee

 

LeeMac,

 

This code is perfect but I do have one question. When using this, if the resulting value ends in a zero, say 100.30 the end result is 100.3. How can I modify this to keep the hundredth mark even if zero?

 

Thanks!!

Share this post


Link to post
Share on other sites
Lee Mac
LeeMac,

 

This code is perfect but I do have one question. When using this, if the resulting value ends in a zero, say 100.30 the end result is 100.3. How can I modify this to keep the hundredth mark even if zero?

 

Thanks!!

 

Hi Cylis,

 

There is an updated version of this program posted here; the updated version will use your settings for LUPREC & DIMZIN when formatting non-integer values.

 

Lee

Share this post


Link to post
Share on other sites
Cylis0509
Hi Cylis,

 

There is an updated version of this program posted here; the updated version will use your settings for LUPREC & DIMZIN when formatting non-integer values.

 

Lee

 

Thank you Lee! Works like a dream!

Share this post


Link to post
Share on other sites
Lee Mac

You're welcome!

Share this post


Link to post
Share on other sites
JHayes

Hey guys, this is a great routine (Thanks, Lee)

But how can we modify it to work on multileader text also?

Share this post


Link to post
Share on other sites
surajake

hi all,

can anyone help me, to make the same lisp without decimal values. :)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...