dtext with numbers rounding off from three to two decimals

Discussion in 'AutoCAD' started by Laura, Dec 6, 2004.

  1. Laura

    Laura Guest

    I've a drawing with a lot of numbers with 3 decimals (all dtext).

    Is there a easy/quick way in AutoCAD2005 to round those numbers off to two
    decimals?

    For Example:

    2.841 changing in 2.84

    2.639 changing in 2.64

    etc.

    Or has it to be done in a lisproutine?



    greetings



    Laura
     
    Laura, Dec 6, 2004
    #1
  2. Laura

    ECCAD Guest

    Yes, (can) be done with Lisp.
    Have you used (rtos) function ?
    Do:
    (setq n "2.841")
    "2.841"
    (setq n (rtos (atof n) 2 2))
    "2.84"


    Bob
     
    ECCAD, Dec 6, 2004
    #2
  3. Laura

    ECCAD Guest

    Here is a program to do the Dtext ..
    Cut-paste in Notepad, save as 'rnd-txt2.lsp', under
    your support folder. To load at command: prompt, do:
    (load "rnd-txt2")


    ;; rnd-txt2.lsp
    ;; round off text to (2) decimal points
    (defun C:RND-TXT2 (/ cnt ss attlist attval)
    (prompt "\nPick the Text to round-off to 2 decimal places:")
    (setq ss (ssget))
    (if ss
    (progn
    (setq cnt 0)
    (repeat (sslength ss)
    (setq ent (ssname ss cnt))
    (setq elist (entget ent))
    (setq ename (cdr (assoc 0 elist)))
    (if (= ename "TEXT")
    (progn
    (setq txt (cdr (assoc 1 elist)))
    (setq txt (rtos (atof txt) 2 2))
    ;; (setq txt (rtos (atof txt) 2 3)); 3 decimal places
    (entmod (setq elist (subst (cons 1 txt)(assoc 1 elist) elist))); replace it
    (entupd ent); update entity
    ); progn
    ); if
    (setq cnt (1+ cnt))
    );end repeat
    );end progn
    );end if
    (princ)
    ); function

    Bob
     
    ECCAD, Dec 6, 2004
    #3
  4. Laura

    ECCAD Guest

    ;; rnd-txt2.lsp
    ;; round off text to (2) decimal points
    (defun C:RND-TXT2 (/ cnt ss ent elist ename txt)
    (prompt "\nPick the Text to round-off to 2 decimal places:")
    (setq ss (ssget))
    (if ss
    (progn
    (setq cnt 0)
    (repeat (sslength ss)
    (setq ent (ssname ss cnt))
    (setq elist (entget ent))
    (setq ename (cdr (assoc 0 elist)))
    (if (= ename "TEXT")
    (progn
    (setq txt (cdr (assoc 1 elist)))
    (setq txt (rtos (atof txt) 2 2))
    ;; (setq txt (rtos (atof txt) 2 3)); 3 decimal places
    (entmod (setq elist (subst (cons 1 txt)(assoc 1 elist) elist))); replace it
    (entupd ent); update entity
    ); progn
    ); if
    (setq cnt (1+ cnt))
    );end repeat
    );end progn
    );end if
    (princ)
    ); function

    Updated defun line...
     
    ECCAD, Dec 6, 2004
    #4
  5. Laura

    Laura Guest

    I was looking for "rtos" but I couldn't find it.
    Thank you very much! This is working!

    greetings Laura
     
    Laura, Dec 7, 2004
    #5
  6. Laura

    Adesu Guest

    or try this

    ; rt is stand for revised text
    ; Design by Ade Suharna <>
    ; 1 December 2004
    ; Program no. 145/12/2004
    ; Edit by
    (defun c:rt (/ ent info1 opt remtex revtex ed)
    (while
    (setq ent (entget (car (entsel "\nCLICK TEXT FOR EDIT:"))))
    (setq info1 (cdr (assoc 1 ent)))
    (setq opt (getstring T "\nENTER NEW TEXT TO INSERT IT: "))
    (setq remtex (getstring T "\nENTER OLD TEXT TO REMOVE: "))
    (setq revtex (vl-string-subst opt remtex info1))
    (setq ed (subst (cons 1 revtex)(assoc 1 ent) ent))
    (entmod ed)
    )
    (princ)
    )
     
    Adesu, Dec 9, 2004
    #6
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.