ScoRm Posted July 24, 2018 Share Posted July 24, 2018 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 Quote Link to comment Share on other sites More sharing options...
BIGAL Posted July 25, 2018 Share Posted July 25, 2018 Look at the help for (Rtos x 2 0) (RTOS x decimal numdecimalplaces) Quote Link to comment Share on other sites More sharing options...
ronjonp Posted July 25, 2018 Share Posted July 25, 2018 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)))) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.