Jump to content

Rounding TEXT into 2 decimal places


ScoRm

Recommended Posts

okay, please keep in mind, I do not have any training about lisp or any programing.

I only come up with this code by searching and I'm stuck! I need someones help

i copied some code, so I do not own any of it...

all I want is to select some text objects and round it to 2 decimal places.

 

 

 

(defun c:rrounding (/ ss d e)
 (and (setq obj (car (entsel "\nPick text object :")))
      (setq obj (vlax-ename->vla-object obj))
      (wcmatch (vla-get-objectname obj) "AcDb*Text")

      (/= "" ())

      (vla-put-textstring obj (LM:roundto atof(obj) 2))
 )

;(setq ss (ssget "_:S" '((0 . "MTEXT,TEXT"))))
;(LM:roundto atof(ss) 2)

 (princ)
)

(defun LM:roundto ( n p )
   (LM:roundm n (expt 10.0 (- p)))
)

(defun LM:roundm ( n m )
   (* m (atoi (rtos (/ n (float m)) 2 0)))
)

I Admit, IDK what i'm doing im sorry

Link to comment
Share on other sites

Try this:

(defun c:rrounding (/ obj)
 (and (setq obj (car (entsel "\nPick text object :")))
      (setq obj (vlax-ename->vla-object obj))
      (wcmatch (vla-get-objectname obj) "AcDb*Text")
      (vla-put-textstring obj (rtos (lm:roundto (atof (vla-get-textstring obj)) 2) 2 2))
 )
 (princ)
)
;; Multiple selection
(defun c:foo (/ o s)
 (if (setq s (ssget ":L" '((0 . "*text"))))
   (foreach a (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
     (setq o (vlax-ename->vla-object a))
     (vla-put-textstring o (rtos (lm:roundto (atof (vla-get-textstring o)) 2) 2 2))
   )
 )
 (princ)
)
(defun lm:roundto (n p) (lm:roundm n (expt 10.0 (- p))))
(defun lm:roundm (n m) (* m (atoi (rtos (/ n (float m)) 2 0))))

Link to comment
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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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...