TunzaGibbo Posted June 14, 2018 Share Posted June 14, 2018 (defun c:www (/ P1 P2 Dist1 Dist2 Ang1 hole1a hole1b) (savevartoold) (setq P1 (getpoint "\n Select a Point : ")) (setq P2 (getpoint P1 "\n Select a Point : ")) (setq Dist1 (distance P1 P2)) (setq Dist2 (- Dist1 40.0)) (setq Ang1 (angle P1 P2)) (setvar "osmode" 0) (command "_.circle" (polar P1 (+ ang1 (dtr 0)) 20.0) "D" 3.2 "" ) (setq hole1a (entlast)) (command "_.circle" (polar P1 (+ ang1 (dtr 0)) (- Dist1 20.0)) "D" 3.2 "" ) (setq hole1b (entlast)) (if (and (> (- Dist1 40) 200) (/> (- Dist1 40) 400)) (setq NewDist (/ (- Dist1 40) 2))) (command "_.copy" hole1a "" (polar P1 (+ ang1 (dtr 0)) 20) NewDist) "") (resetoldvar) (princ) ) It all works perfect until I get to the "if" What I'm trying to say is that if Dist1 minus 40 is greater than 200 or Dist1 minus 40 is not greater than 400 then set NewDist to Dist1 minus 40 divided by 2. I hope I have explained that well enough Regards Quote Link to comment Share on other sites More sharing options...
Aftertouch Posted June 14, 2018 Share Posted June 14, 2018 The /> wont work. Its either: > larger than... => larger or equal = So... /> 400 had to be ' Quote Link to comment Share on other sites More sharing options...
rkmcswain Posted June 14, 2018 Share Posted June 14, 2018 There is no "not greater than" function [/>] Use less than or less than or equal Ref: http://help.autodesk.com/view/ACD/2016/ENU/?guid=GUID-EBDC1072-48BF-4204-80B1-73430DBF58E1 Quote Link to comment Share on other sites More sharing options...
TunzaGibbo Posted June 14, 2018 Author Share Posted June 14, 2018 thanks for the advice I need to write a series of conditions for example >200 but not > than 400 >200 but not > than 600 >200 but not > than 800 and so on up to 3400 Quote Link to comment Share on other sites More sharing options...
Aftertouch Posted June 14, 2018 Share Posted June 14, 2018 i suggest to use a 'COND' function instead of the 'IF' function. (cond ((and (> 200 dist1) (< 400 dist1)) (princ "i am more than 200 and less then 400.") ) ((and (> 200 dist1) (< 600 dist1)) (princ "i am more than 200 and less then 600.") ) ((and (> 200 dist1) (< 800 dist1)) (princ "i am more than 200 and less then 800.") ) ((and (> 200 dist1) (< 1000 dist1)) (princ "i am more than 200 and less then 1000.") ) (t (princ "i am not any of the above..") ) ) Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted June 14, 2018 Share Posted June 14, 2018 Dist1 minus 40 is greater than 200 or Dist1 minus 40 is not greater than 400 then set NewDist to Dist1 minus 40 divided by 2. hi, just confused how negative value -40 can be greater than positif +400 ? (< 200 ([color="blue"]abs[/color] dist1) 400)) ? or not? Quote Link to comment Share on other sites More sharing options...
Aftertouch Posted June 14, 2018 Share Posted June 14, 2018 hi, just confused how negative value -40 can be greater than positif +400 ? (< 200 ([color="blue"]abs[/color] dist1) 400)) ? or not? He doesnt want a negative 40 (-40). He wants his dist1, lowered with 40. ;-) Quote Link to comment Share on other sites More sharing options...
ronjonp Posted June 14, 2018 Share Posted June 14, 2018 i suggest to use a 'COND' function instead of the 'IF' function. (cond ((and (> 200 dist1) (< 400 dist1)) (princ "i am more than 200 and less then 400.") ) ((and (> 200 dist1) (< 600 dist1)) (princ "i am more than 200 and less then 600.") ) ((and (> 200 dist1) (< 800 dist1)) (princ "i am more than 200 and less then 800.") ) ((and (> 200 dist1) (< 1000 dist1)) (princ "i am more than 200 and less then 1000.") ) (t (princ "i am not any of the above..") ) ) FWIW .. you could simplify your code to this: (setq dist (- dist1 40)) (cond ((< 200 dist1 400) (princ "i am more than 200 and less then 400.")) ((< 200 dist1 600) (princ "i am more than 200 and less then 600.")) ((< 200 dist1 800) (princ "i am more than 200 and less then 800.")) ((< 200 dist1 1000) (princ "i am more than 200 and less then 1000.")) ((princ "i am not any of the above..")) ) Quote Link to comment Share on other sites More sharing options...
Grrr Posted June 14, 2018 Share Posted June 14, 2018 I remember writing some findrange subfoo and thought its cool ;| Example (setq val 63) (findrange val '( ( (0 51) "01") ( (52 76) "02") ( (77 121) "03") ( (122 176) "04") ( (177 nil) "05") ) ) >> "02" |; (setq findrange (lambda (v L) (if (and (numberp v) (listp L)) (vl-some '(lambda (x / mn mx) (setq mn (caar x)) (setq mx (cadar x)) (if (apply '<= (append (if mn (list mn)) (list v) (if mx (list mx)) )) (cadr x) ); if ); lambda L ); vl-some ); if ); lambda (v L) ); setq findrange Quote Link to comment Share on other sites More sharing options...
ronjonp Posted June 14, 2018 Share Posted June 14, 2018 Very cool Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 14, 2018 Share Posted June 14, 2018 FWIW .. you could simplify your code to this: (setq dist (- dist1 40)) (cond ((< 200 dist1 400) (princ "i am more than 200 and less then 400.")) ((< 200 dist1 600) (princ "i am more than 200 and less then 600.")) ((< 200 dist1 800) (princ "i am more than 200 and less then 800.")) ((< 200 dist1 1000) (princ "i am more than 200 and less then 1000.")) ((princ "i am not any of the above..")) ) Which could be simplified further to - (setq dist (- dist1 40)) (cond ((<= dist1 200) (princ "\nI am less than 200.")) ((< dist1 400) (princ "\nI am more than 200 and less than 400.")) ((< dist1 600) (princ "\nI am more than 200 and less than 600.")) ((< dist1 800) (princ "\nI am more than 200 and less than 800.")) ((< dist1 1000) (princ "\nI am more than 200 and less than 1000.")) ((princ "\nI am more than 1000.")) ) Quote Link to comment Share on other sites More sharing options...
ronjonp Posted June 14, 2018 Share Posted June 14, 2018 Which could be simplified further to -(setq dist (- dist1 40)) (cond ((<= dist1 200) (princ "\nI am less than 200.")) ((< dist1 400) (princ "\nI am more than 200 and less than 400.")) ((< dist1 600) (princ "\nI am more than 200 and less than 600.")) ((< dist1 800) (princ "\nI am more than 200 and less than 800.")) ((< dist1 1000) (princ "\nI am more than 200 and less than 1000.")) ((princ "\nI am more than 1000.")) ) But of course .. sometimes I cannot see the forest through the trees. Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted June 14, 2018 Share Posted June 14, 2018 He doesnt want a negative 40 (-40).He wants his dist1, lowered with 40. ;-) Thanks this makes sence now arithmetic minus negative (defun foo (n l) (eval (cons 'cond (append (mapcar '(lambda (x) (list (cons '<= (list 200. n x)) [color="green"];(<= 200. n x) [/color] (list 'princ (strcat "i am more than 200 and less than " (vl-princ-to-string x))) ) ) l ) '((t (if (< n 200.) (princ "\nI am less than 200.") (princ "i am not any of the above..") ) ) ) ) ) ) ) ([color="blue"]foo[/color] (setq dist1 (- dist1 40)) '(400 600 800 1000 1500 2000 2500 3000) ) IMO, other options too? Ronjonp is used to vl-remove-if- function, perhaps Lee, grr or others would share some variants assoc list & vl-sort etc..? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 14, 2018 Share Posted June 14, 2018 A variant using vl-some (setq d (- dist1 40)) (or (vl-some '(lambda ( x ) (if (< d x) (princ (strcat "\nI am less than " (rtos x))))) '(200 400 600 800 1000)) (princ "\nI am greater than 1000.") ) Quote Link to comment Share on other sites More sharing options...
Tharwat Posted June 14, 2018 Share Posted June 14, 2018 Another. (or (and (setq p (vl-position t (mapcar '(lambda (x) (< (- dist1 40) x)) (setq l '(200 400 600 800 1000))))) (princ (strcat "\nI am less than " (itoa (nth p l)))) ) (princ "\nI am greater than 1000.") ) Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted June 15, 2018 Share Posted June 15, 2018 I remember writing some findrange subfoo and thought its cool findrange accepts nil ! nice simplified version - it does not support nil (minimal tested) (cadar (vl-remove-if-not '(lambda (x) (= 1 (vl-position 0 (vl-sort-i (cons n (car x)) '<) ))) l) ) A variant using vl-some Another. better variant as expected ! Quote Link to comment Share on other sites More sharing options...
Tharwat Posted June 15, 2018 Share Posted June 15, 2018 better variant as expected ! Thank you. Quote Link to comment Share on other sites More sharing options...
Grrr Posted June 15, 2018 Share Posted June 15, 2018 findrange accepts nil ! nice Thanks han, you can provide arguments like '( ((nil 30) "I'm below or equal to thirty") ((40 nil) "I'm above or equal to forty") (nil "I'm something else, in this case between 30-40 (exclusive)") ) Quote Link to comment Share on other sites More sharing options...
TunzaGibbo Posted June 16, 2018 Author Share Posted June 16, 2018 Thank you all for the help. The "cond" now works fine I'm puzzled with the command "copym" It works on the command line but not in lisp. Does anyone know why this may be because this command suits my purpose perfectly. (defun c:ww (/ P1 P2 P3 P4 Ang1 Dist1 Dist2 hole1a hole1b Copies) (savevartoold) (setq P1 (getpoint "\n Select a Point : ")) (setq P2 (getpoint P1 "\n Select a Point : ")) (setq Dist1 (distance P1 P2)) (setq Dist2 (- Dist1 40.0)) (setq Ang1 (angle P1 P2)) (setq P3 (polar P1 (dtr 0) 20)) (setq P4 (polar P3 (dtr 0) Dist2)) (cond ((and (> Dist2 1) (< Dist2 200)) (setq Copies 1)) ((and (> Dist2 200) (< Dist2 400)) (setq Copies 2)) ((and (> Dist2 200) (< Dist2 600)) (setq Copies 3)) ((and (> Dist2 200) (< Dist2 800)) (setq Copies 4)) ((and (> Dist2 200) (< Dist2 1000)) (setq Copies 5)) ((and (> Dist2 200) (< Dist2 1200)) (setq Copies 6)) ) (setvar "osmode" 0) (command "_.circle" (polar P1 (+ ang1 (dtr 0)) 20.0) "D" 3.2 "" ) (setq hole1a (entlast)) (command "copym" hole1a "" P3 "d" P4 Copies "") Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted June 17, 2018 Share Posted June 17, 2018 Thank you all for the help.The "cond" now works fine I'm puzzled with the command "copym" It works on the command line but not in lisp. Does anyone know why this may be because this command suits my purpose perfectly. 1. IMO, in your case no needs cond , suggestions colored 2. (c:copym) ; is a command of express tool not a common command 3. (dtr 0) = 0 (defun c:ww (/ P1 P2 P3 P4 Ang1 Dist1 Dist2 hole1a hole1b Copies) (savevartoold) (if (and (setq P1 (getpoint "\n Select a Point : ")) (setq P2 (getpoint P1 "\n Select a Point : ")) (setq Dist1 (distance P1 P2) Dist2 (- Dist1 40.0) Ang1 (angle P1 P2) P3 (polar P1 [color="red"]0.0[/color] 20.) P4 (polar P3 [color="red"]0.0[/color] Dist2) [b]Copies[/b] [color="red"](if (< 0.0 Dist2 1200.) (1+ (fix (/ Dist2 200.))) ) [/color] ) [color="red"](setq hole1a (entmakex (list '(0 . "CIRCLE") (cons 10 (polar P1 (+ ang1 0.) 20.0)) '(40 . 3.2))))[/color] ) [color="red"] (vl-cmdf "-array" "_non" hole1a "" "r" 1 Copies (/ (distance p3 p4) Copies)) [/color][color="green"]; like this??[/color] [color="green"];;; (acet-copym-divide (ssadd hole1a) p3 p4 copies) ;express tool [/color] (alert [color="purple"]"\nLimits! 0 < x < 1200 !!"[/color]) ) (princ) ) p/s: im not familiar with 'command' call , "_non" instead of (setvar 'osmode 0) not tested. i prefer vla-arrayrectangular 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.