Visual LISP, AutoLISP and General Customization

Reply
Active Member
Posts: 7
Registered: ‎09-02-2013
Message 1 of 4 (362 Views)
Accepted Solution

Rounding up block coordinates (insertion point)

362 Views, 3 Replies
09-02-2013 11:55 PM

Maybe anyone has an idea on the following issue:

We have several AutoCAD drawings with hundreds of block references inserted with imprecise coordinates. Now we need to dimension all elements and need to correct these positions.

I am searching for a routine to round these positions up or down towards a 5mm precision so I don't have to manually move every single block element.

Is there any way to automate the task or do you know any workaround (like inserting the elements into a drawing with poorer unit precision settings)?

 

Thank you very much for your support!

:smileyhappy:

*Expert Elite*
Lee_Mac
Posts: 1,051
Registered: ‎12-29-2009
Message 2 of 4 (328 Views)

Re: Rounding up block coordinates (insertion point)

09-03-2013 04:28 AM in reply to: AIGmbH

Try the following simple program:

 

(defun c:roundins ( / e i m p s x )
    (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 . "INSERT"))))
        (repeat (setq i (sslength s))
            (setq e (entget (ssname s (setq i (1- i))))
                  p (assoc 10 e)
            )
            (entmod (subst (cons 10 (mapcar '(lambda ( x ) (round x m)) (cdr p))) p e))
        )
    )
    (princ)
)

;; Doug Broad
(defun round ( value to )
    (setq to (abs to))
    (* to (fix (/ ((if (minusp value) - +) value (* to 0.5)) to)))
)
(princ)
Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)
Expert Elite
With Mathematics there is the possibility of perfect rigour, so why settle for less?
Active Member
Posts: 7
Registered: ‎09-02-2013
Message 3 of 4 (303 Views)

Re: Rounding up block coordinates (insertion point)

09-03-2013 05:01 AM in reply to: Lee_Mac

Brilliant!

Your script worked perfectly.

Thank you very much.

:smileywink:

*Expert Elite*
Lee_Mac
Posts: 1,051
Registered: ‎12-29-2009
Message 4 of 4 (297 Views)

Re: Rounding up block coordinates (insertion point)

09-03-2013 05:09 AM in reply to: AIGmbH

You're welcome :smileyhappy:

 

Be sure to mark the post as the accepted solution so as to indicate that the thread is resolved :smileywink:

Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)
Expert Elite
With Mathematics there is the possibility of perfect rigour, so why settle for less?

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community