Tomislav Posted July 28, 2017 Posted July 28, 2017 Hello. Does anyone have a routine that would round the coordinates of selected points,lines,polylines and splines to 2 decimal places(not just cut the rest of decimal places but ROUND it, so .384=.38 and .385=.39) and move them to that coordinates.That applies to height also. In case of polys and splines the vertices should also be rounded... thanx Quote
MJLM Posted July 28, 2017 Posted July 28, 2017 You can parse through your entities one by one with a while loop and use the following syntax (atof (rtos 0.384 2 2)) An example for lines and points would be as follows. You will need to elaborate a bit for other kinds of entities but the principle is the same. (defun fixl (/ round_decimals ss cnt pt10 pt11 lndt) (setq round_decimals 6) (if (setq ss (ssget "_A" '((-4 . "<OR") (0 . "LINE") (0 . "POINT") (-4 . "OR>")))) (progn (setq cnt (sslength ss)) (while (>= (setq cnt (1- cnt)) 0) (setq lndt (entget (ssname ss cnt))) (setq pt10 (mapcar 'atof (mapcar '(lambda (x) (rtos x 2 round_decimals)) (cdr (assoc 10 lndt))))) (setq lndt (subst (cons 10 pt10) (assoc 10 lndt) lndt)) (entmod lndt) (if (assoc 11 lndt) ; this condition is used for lines (progn (setq pt11 (mapcar 'atof (mapcar '(lambda (x) (rtos x 2 round_decimals)) (cdr (assoc 11 lndt))))) (setq lndt (subst (cons 11 pt11) (assoc 11 lndt) lndt)) (entmod lndt) ) ) ) ) ) ) Quote
Lee Mac Posted July 28, 2017 Posted July 28, 2017 I posted an example here some time ago: https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/rounding-of-line-and-pline-vertices/m-p/4396563#M314796 Quote
Grrr Posted July 28, 2017 Posted July 28, 2017 I posted an example here some time ago:https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/rounding-of-line-and-pline-vertices/m-p/4396563#M314796 Awesome routine, Lee! I've found that thread some time ago, but then I lost it and couldn't find it again, thanks for reposting it ! Quote
Tomislav Posted July 29, 2017 Author Posted July 29, 2017 thank you all for your help , I guess I'll try to implement rounding for splines too, if that's possible... Quote
szalonypl Posted May 9 Posted May 9 Hi. Is there any chance that this program will also work local UCS? Quote
szalonypl Posted May 9 Posted May 9 (edited) I think i figure it out. ;;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/rounding-of-line-and-pline-vertices/m-p/4396563#M314796 (defun c:round ( / e i k l m s ) (setq l '( ("CIRCLE" 10 40) ("LINE" 10 11) ("LWPOLYLINE" 10) ("INSERT" 10) ("POINT" 10) ) ) (if (null *tol*) (setq *tol* 5.0) ) (initget 6) (if (setq m (getreal (strcat "\nSpecify rounding tolerance <" (rtos *tol*) ">: "))) (setq *tol* m) (setq m *tol*) ) (if (setq s (ssget "_:L" '((0 . "CIRCLE,LINE,LWPOLYLINE,INSERT,POINT")))) (repeat (setq i (sslength s)) (if (setq e (entget (ssname s (setq i (1- i)))) k (cdr (assoc (cdr (assoc 0 e)) l)) ) (entmod (rounddxf k m e)) ) ) ) (princ) ) (defun rounddxf ( key mod lst / rtn ) (foreach itm lst (if (member (car itm) key) (setq rtn (cons (cons (car itm) (roundvalue (cdr itm) mod)) rtn)) (setq rtn (cons itm rtn)) ) ) (reverse rtn) ) (defun roundvalue ( val mod ) (if (listp val) (progn (setq val (trans val 0 1)) (setq val (mapcar '(lambda ( x ) (round x mod)) val)) (setq val (trans val 1 0)) ) (round val mod) ) ) ;; Doug Broad (defun round ( value to ) (setq to (abs to)) (* to (fix (/ ((if (minusp value) - +) value (* to 0.5)) to))) ) (princ) Here: (defun roundvalue ( val mod ) (if (listp val) (progn (setq val (trans val 0 1)) (setq val (mapcar '(lambda ( x ) (round x mod)) val)) (setq val (trans val 1 0)) ) (round val mod) ) ) Edited May 9 by SLW210 Added Code Tags!! Quote
SLW210 Posted May 9 Posted May 9 Please use Code Tags in the future, not quote tags, for your code. (<> in the editor toolbar) 1 Quote
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.