Inserting a + in DTEXT

Discussion in 'AutoCAD' started by lee7598, Jun 2, 2004.

  1. lee7598

    lee7598 Guest

    I am looking for a routine that will allow me to window multiple text blocks and insert a +(plus) in between the second and third digit from the right, for example: 4+00, 150+00, 156+96.36, etc. Sometimes there is a decimal, other times there is not. If anyone could offer some suggestions it would be greatly appreciated.
     
    lee7598, Jun 2, 2004
    #1
  2. lee7598

    Jeff Mishler Guest

    Here ya go..... it even checks and corrects for numbers less than 100 (
    15.00 -> 0+15.00, 3.9 -> 0+03.9) and removes any commas that may exist.

    Jeff

    (defun c:txt2sta (/ DECIMAL DOC NEWTXT POST+ PRE+ SS TXT)
    (vl-load-com)
    (if (ssget '((0 . "TEXT")))
    (progn
    (setq doc (vla-get-activedocument
    (vlax-get-acad-object))
    ss (vla-get-activeselectionset doc)
    )
    (vla-startundomark doc)
    (vlax-for x ss
    (setq txt (vla-get-textstring x))
    (if (wcmatch txt "*`,*")
    (setq txt (vl-list->string
    (vl-remove (ascii ",")
    (vl-string->list txt))))
    )
    (if (setq decimal (vl-string-position (ascii ".") txt 0))
    (progn
    (cond ((= 2 decimal)(setq txt (strcat "0" txt)
    decimal (1+ decimal)))
    ((= 1 decimal)(setq txt (strcat "00" txt)
    decimal (+ 2 decimal)))
    ((= 0 decimal)(setq txt (strcat "000" txt)
    decimal (+ 3 decimal)))
    )
    (setq pre+ (substr txt 1 (- decimal 2))
    post+ (substr txt (- decimal 1))
    newtxt (strcat pre+ "+" post+)
    )
    )
    (progn
    (cond ((= 2 (strlen txt))(setq txt (strcat "0" txt)))
    ((= 1 (strlen txt))(setq txt (strcat "00" txt)))
    )
    (setq pre+ (substr txt 1 (- (strlen txt) 2))
    post+ (substr txt (- (strlen txt) 1))
    newtxt (strcat pre+ "+" post+)
    )
    )
    )
    (vla-put-textstring x newtxt)
    )
    (vla-endundomark)
    )
    )
    (princ)
    )
    blocks and insert a +(plus) in between the second and third digit from the
    right, for example: 4+00, 150+00, 156+96.36, etc. Sometimes there is a
    decimal, other times there is not. If anyone could offer some suggestions
    it would be greatly appreciated.
     
    Jeff Mishler, Jun 2, 2004
    #2
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.