mickydee81 Posted June 23, 2015 Share Posted June 23, 2015 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 Quote Link to comment Share on other sites More sharing options...
tombu Posted June 23, 2015 Share Posted June 23, 2015 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.00000000008 rounded to the nearest multiple of 4 is 8 Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 23, 2015 Share Posted June 23, 2015 Just be careful if your text is formatted MText, since for such cases the text content will contain numerical formatting codes. Quote Link to comment Share on other sites More sharing options...
mickydee81 Posted June 23, 2015 Author Share Posted June 23, 2015 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.00000000008 rounded 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 Quote Link to comment Share on other sites More sharing options...
tombu Posted June 24, 2015 Share Posted June 24, 2015 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. Quote Link to comment Share on other sites More sharing options...
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.