Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Rounding of Line and Pline Vertices

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
AIGmbH
2418 Views, 6 Replies

Rounding of Line and Pline Vertices

Here's another one, concerning the same inaccurate drawing. Now I have all block instances rounded into a 5mm-accuracy.

Does anyone have a glue how to also round in Line start and end points (and maybe even polyline vertices) into a 1mm (or custom) accuracy. There are hundreds of inaccurate line elements within the drawing Smiley Frustrated !!

6 REPLIES 6
Message 2 of 7
Lee_Mac
in reply to: AIGmbH

Here is a generalised version of the previous program:

 

(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)
        (mapcar '(lambda ( x ) (round x mod)) val)
        (round val mod)
    )
)

;; Doug Broad
(defun round ( value to )
    (setq to (abs to))
    (* to (fix (/ ((if (minusp value) - +) value (* to 0.5)) to)))
)
(princ)
Message 3 of 7
Kent1Cooper
in reply to: AIGmbH


@AIGmbH wrote:

....

Does anyone have a glue how to also round in Line start and end points (and maybe even polyline vertices) into a 1mm (or custom) accuracy. There are hundreds of inaccurate line elements within the drawing Smiley Frustrated !!


This has come up here before.  For instance, this thread, but I think there are more if you Search a little.

Kent Cooper, AIA
Message 4 of 7
AIGmbH
in reply to: Lee_Mac

Another seamlessly working script!

This is exactly what I was looking for. An wholistic approach to the "snap to grid" problem - at least for the basic drawing elements that I was struggling with. When it comes to architectural elements like walls and foils the script would have to be further extended, but I guess even this would be possible.

Thank you!

Message 5 of 7
Lee_Mac
in reply to: AIGmbH

Message 6 of 7
Jozef.lovas
in reply to: Lee_Mac

Perfect.

This is exactly what I was looking for.

I would need small modification.

For my geodetic plan I need to round even numbers always up

e.g.

if rounding tolerance = 0.01

then results should be following:

1.134 -> 1.13
1.135 -> 1.14
1.136 -> 1.14
1.141 -> 1.14
1.145 -> 1.14
1.149 -> 1.14

Message 7 of 7
90491929
in reply to: Lee_Mac

Hi @Lee_Mac , thanks for this. Is it possible for this to work in UCS also?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost