Jump to content

points,lines,polylines,splines coordinate round up


Recommended Posts

Posted

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

Posted

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

Posted

thank you all for your help :thumbsup: , I guess I'll try to implement rounding for splines too, if that's possible...

  • 7 years later...
Posted

Hi.
Is there any chance that this program will also work local UCS?

Posted (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 by SLW210
Added Code Tags!!
Posted

Please use Code Tags in the future, not quote tags, for your code. (<> in the editor toolbar)

  • Like 1

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