TunzaGibbo 发表于 2022-7-5 15:09:44

“如果”


(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)   
)

 
在我找到“如果”之前,一切都很完美
 
我想说的是,如果Dist1-40大于200或者Dist1-40不大于400,那么将NewDist设置为Dist1-40除以2。
我希望我已经解释得足够清楚了
 
当做

Aftertouch 发表于 2022-7-5 15:13:56

/>不起作用。
 
其一:
>大于。。。
=>大于或等于
=
 
所以…/>400必须是'

rkmcswain 发表于 2022-7-5 15:18:35

没有“不大于”功能[/>]
 
使用小于或小于或等于
 
裁判:http://help.autodesk.com/view/ACD/2016/ENU/?guid=GUID-EBDC1072-48BF-4204-80B1-73430DBF58E1

TunzaGibbo 发表于 2022-7-5 15:20:05

谢谢你的建议
 
我需要写一系列条件,例如
>200但不大于400
>200但不大于600
>200但不大于800
以此类推,最多3400个

Aftertouch 发表于 2022-7-5 15:23:06

我建议使用“COND”函数而不是“IF”函数。
 

(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..")
)
)

hanhphuc 发表于 2022-7-5 15:26:52

嗨,我只是想知道负值-40怎么会大于正定值+400?
(< 200 (abs dist1) 400)) ?
还是没有?

Aftertouch 发表于 2022-7-5 15:30:08

 
他不想要负40(-40)。
他想要他的dist1,降低到40

ronjonp 发表于 2022-7-5 15:34:19

 
不管好坏您可以将代码简化为:
(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.."))
)

Grrr 发表于 2022-7-5 15:36:55

我记得写过一些芬德兰奇的Subfo,觉得很酷
 
;| 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

ronjonp 发表于 2022-7-5 15:39:31

另一个
(setq dist (- dist1 40))
(cond ((<= dist1200) (princ "\nI am less than 200."))
   ((<dist1400) (princ "\nI am more than 200 and less than 400."))
   ((<dist1600) (princ "\nI am more than 200 and less than 600."))
   ((<dist1800) (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."))
)
页: [1] 2
查看完整版本: “如果”