Lisp to round text (with numbe
Hi all,First post, was hoping to get some help.
I need a lisp that will round a number in autocad to the nearest 0.05, I have a numerous drawings with bench levels for lots (civil), I would like to be able to swipe multiple pieces of text and round them all to nearest 0.05.
Any help with this would be much appreciated
Cheers I've seen many versions of this over the years, but this was the first one I saw and it still works.
;;; Written by Doug Broad;;; If value given 'to' argument is a real, a real is returned.;;; Rounds to nearest multiple of 'to' real or integer.(defun round (value to / try) (setq to (abs to)) (* to (fix (/ ((if (minusp value) - +) value (* to 0.5)) to)))); examples:; (round 12232e-015 1); 0; (round 12232e-015 1.0); 0.0; (round 123.6 1.0); 124.0; (round -123.6 1.0); -124.0; (round 6.00000000008 4); 8; 6.00000000008rounded to the nearest multiple of 4 is 8 Just be careful if your text is formatted MText, since for such cases the text content will contain numerical formatting codes. Hi guys,
thanks for the help.
I changed it to this
;;; Written by Doug Broad
;;; If value given 'to' argument is a real, a real is returned.
;;; Rounds to nearest multiple of 'to' real or integer.
(defun c:bench (value to / try)
(setq to (abs to))
(* to (fix (/ ((if (minusp value) - +) value (* to 0.5)) to)))
)
; examples:
; (round 12232e-015 1)
; 0
; (round 12232e-015 1.0)
; 0.0
; (round 123.6 1.0)
; 124.0
; (round -123.6 1.0)
; -124.0
; (round 6.00000000008 4)
; 8
; 6.00000000008rounded to the nearest multiple of 4 is 8
when I type bench into the command line I get this message '; error: too few arguments'
Not sure what im doing wrong. I have no real experience writing lisp code. Have I missed something?
Thanks again for your help You need to use the original code, look at the examples.To round 1.2345 to the nearest 0.05 enter (round 1.2345 0.05)
It's set up this way so you can easily call it from another routine using the "value" you want to round and the "to" you want it rounded to.
A command function that starts with "c:" cannot have the "value" and "to" arguments.For a command function you would have to add prompts for and save those values.
页:
[1]