Lee Mac Posted September 30, 2016 Posted September 30, 2016 From Doug Broad I believe: (defun round ( value to ) (setq to (abs to)) (* to (fix (/ ((if (minusp value) - +) value (* to 0.5)) to))) ) _$ (round 13 2) 14 Quote
Roy_043 Posted September 30, 2016 Posted September 30, 2016 Not sure what mousho wants: ; Round to first even number in the direction of pos. or neg. infinity. ; (RoundToEvenInf 12.1) => 14 ; (RoundToEvenInf -12.1) => -14 (defun RoundToEvenInf (num) (if (zerop (rem num 2)) num (* 2 (fix ((if (minusp num) - +) (/ num 2.0) 1))) ) ) ; Round to first even number in the direction of pos. infinity. ; (RoundToEvenUp 12.1) => 14 ; (RoundToEvenUp -12.1) => -12 (defun RoundToEvenUp (num) (if (zerop (rem num 2)) num (* 2 (fix (+ (/ num 2.0) (if (minusp num) 0 1)))) ) ) Quote
paradonk Posted June 14, 2018 Posted June 14, 2018 (edited) (defun round (number) (setq fixn (fix number)) (if (>= (- number fixn) 0.5) (setq rnum (1+ fixn)) (setq rnum fixn) ) ) Edited June 14, 2018 by SLW210 Code Tags Quote
bogeymen77 Posted March 23, 2019 Posted March 23, 2019 Hi, i would like to "round up" to the next .5 in the area dimension routine that we already use. how can i do that and where to integrate the routine. here's the code that we are using. thank you (defun c:aaa ( / *error* _SelectIf _ObjectID acdoc acspc d1 d2 fieldformatting msg predicate pt ) (setq fieldformatting "%lu2%ct4%qf1 PC ") ;; Field Formatting (defun *error* ( msg ) (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")) (princ (strcat "\nError: " msg)) ) (princ) ) (defun _SelectIf ( msg pred ) ( (lambda ( f / e ) (while (progn (setvar 'ERRNO 0) (setq e (car (entsel msg))) (cond ( (= 7 (getvar 'ERRNO)) (princ "\nMissed, try again.") ) ( (eq 'ENAME (type e)) (if (and f (null (f e))) (princ "\nInvalid Object.") ) ) ) ) ) e ) (eval pred) ) ) (setq acdoc (vla-get-activedocument (vlax-get-acad-object)) acspc (vlax-get-property acdoc (if (= 1 (getvar 'CVPORT)) 'paperspace 'modelspace)) ) (setq _ObjectID (eval (list 'lambda '( obj ) (if (and (vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE")) (vlax-method-applicable-p (vla-get-utility acdoc) 'getobjectidstring) ) (list 'vla-getobjectidstring (vla-get-utility acdoc) 'obj ':vlax-false) '(itoa (vla-get-objectid obj)) ) ) ) ) (setq predicate (function (lambda ( x ) (and (eq (cdr (assoc 0 (setq x (entget x)))) "DIMENSION") (member (boole 4 (+ 128 64 32) (cdr (assoc 70 x))) '(0 1)) ) ) ) ) (while (and (setq d1 (_SelectIf "\nSelect 1st Dimension <Exit>: " predicate)) (setq d2 (_SelectIf "\nSelect 2nd Dimension <Exit>: " predicate)) (setq pt (getpoint "\nPoint for Result <Exit>: ")) ) (vla-addmtext acspc (vlax-3D-point (trans pt 1 0))) 0.0 (strcat "%<\\AcExpr " "%<\\AcObjProp Object(%<\\_ObjId " (_ObjectID (vlax-ename->vla-object d1)) ">%).Measurement>% * " "%<\\AcObjProp Object(%<\\_ObjId " (_ObjectID (vlax-ename->vla-object d2)) ">%).Measurement>% " "\\f \"" fieldformatting "\">%" ) ) ) (princ) ) (vl-load-com) (princ) Quote
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.