whosa Posted September 13, 2019 Share Posted September 13, 2019 Hi Guys, i would like to add a round down 0.50 to this lisp. ex. 15.15 = 15.00 - 15.60=15.50 Exception <0.50 slould be =0 .50 (not 0.00) It is possible? Someone can help me? many thanks (defun C:but ( / e o p d ) (setvar 'errno 0) (and vlax-get-acad-object (while (/= 52 (getvar 'errno)) (setq e (car (nentsel "\nSelect text to fill: "))) (cond ((= 7 (getvar 'errno)) (princ "\nMissed, try again.") (setvar 'errno 0) ) ((and e (not (vlax-property-available-p (setq o (vlax-ename->vla-object e)) 'TextString))) (princ "\nThis is not a text object.") (setq e nil) ) ((and o (eq (vla-get-Lock (vla-item (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object))) (vla-get-Layer o))) :vlax-true)) (princ "\nThis object is on a locked layer.") (setq e nil) ) (e (if (and (setq p (getpoint "\nSpecify first point: ")) (cadr (setq p (cons p (list (getpoint "\nSpecify second point: " p))))) (setq d (rtos (abs (/ (apply '- (mapcar 'last (mapcar '(lambda (x) (trans x 1 0)) p))) 1000.)) 2 2)) ) (cond ( (= "ATTDEF" (cdr (assoc 0 (entget e)))) (vla-put-TagString o d) ) ( T (vla-put-TextString o d) ) ) ) (setvar 'errno 52) ) (T nil) ) ) ) (princ) );| defun |; (or vlax-get-acad-object (vl-load-com)) (princ) Quote Link to comment Share on other sites More sharing options...
Emmanuel Delay Posted September 13, 2019 Share Posted September 13, 2019 Look at http://www.lee-mac.com/round.html function LM:rounddown does what you want, I think. (LM:rounddown 15.15 0.5) Quote Link to comment Share on other sites More sharing options...
whosa Posted September 13, 2019 Author Share Posted September 13, 2019 thanks for your reply. I found this fix but i don't understand how i can add it on my lisp. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 13, 2019 Share Posted September 13, 2019 (edited) 1 hour ago, whosa said: thanks for your reply. I found this fix but i don't understand how i can add it on my lisp. Copy the function definition to the end of your code, and then change this: (setq d (rtos (abs (/ (apply '- (mapcar 'last (mapcar '(lambda (x) (trans x 1 0)) p))) 1000.)) 2 2)) To: (setq d (rtos (LM:rounddown (abs (/ (apply '- (mapcar 'last (mapcar '(lambda (x) (trans x 1 0)) p))) 1000.)) 0.5) 2 2)) @Emmanuel Delay Thanks for the recommendation Edited September 13, 2019 by Lee Mac 2 Quote Link to comment Share on other sites More sharing options...
whosa Posted September 13, 2019 Author Share Posted September 13, 2019 25 minutes ago, Lee Mac said: Copy the function definition to the end of your code, and then change this: (setq d (rtos (abs (/ (apply '- (mapcar 'last (mapcar '(lambda (x) (trans x 1 0)) p))) 1000.)) 2 2)) To: (setq d (rtos (LM:rounddown (abs (/ (apply '- (mapcar 'last (mapcar '(lambda (x) (trans x 1 0)) p))) 1000.)) 0.5) 2 2)) @Emmanuel Delay Thanks for the recommendation Thanks, work really well. I would like to ask you: Is it possible to round UP just when the value is <0.50? Is it possible to get a planar distance between two point insted the height value using the same structure of the lisp? Thank a lot. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 13, 2019 Share Posted September 13, 2019 4 hours ago, whosa said: 1. Is it possible to round UP just when the value is <0.50 Copy the definition for my LM:roundup function to the end of your code, and then change: (setq d (rtos (LM:rounddown (abs (/ (apply '- (mapcar 'last (mapcar '(lambda (x) (trans x 1 0)) p))) 1000.)) 0.5) 2 2)) to: (setq d (abs (/ (apply '- (mapcar 'last (mapcar '(lambda (x) (trans x 1 0)) p))) 1000.)) d (rtos ((if (< d 0.5) LM:roundup LM:rounddown) d 0.5) 2 2) ) 4 hours ago, whosa said: Is it possible to get a planar distance between two point insted the height value using the same structure of the lisp? Copy the function definition for the main program, change the syntax of the copied definition from c:but to c:somethingelse, and change: (setq d (abs (/ (apply '- (mapcar 'last (mapcar '(lambda (x) (trans x 1 0)) p))) 1000.)) d (rtos ((if (< d 0.5) LM:roundup LM:rounddown) d 0.5) 2 2) ) to: (setq d (abs (/ (apply 'distance (mapcar '(lambda ( x ) (list (car x) (cadr x))) p)) 1000.)) d (rtos ((if (< d 0.5) LM:roundup LM:rounddown) d 0.5) 2 2) ) This will calculate the 2D distance between the points in the UCS plane. 1 Quote Link to comment Share on other sites More sharing options...
whosa Posted September 14, 2019 Author Share Posted September 14, 2019 Thanks a lot. You are the guru of the LIPS. I will try it on Monday. Thanks Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 14, 2019 Share Posted September 14, 2019 You're most welcome and thank you for your compliments - let me know how you get on. 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.