明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1021|回复: 9

请各位高手帮我看一下在这里IF为什么没有用?

[复制链接]
发表于 2008-7-12 17:42 | 显示全部楼层 |阅读模式

请各位高手帮我看一下在这里IF为什么没有用?

(defun c:ct(/ ss1 ss2 x)
  (setvar "cmdecho" 1)
  (setq ss1 (ssget))
    (vl-cmdf ".Copy" ss1 "" 0 0)
  (setq ss2 (getstring))
    (cond
      ((/= ss2 "") (vl-cmdf ".Chprop" ss1 "" "layer" ss2 ""))
      ((setq x (cdr (assoc 8 (entget (car(entsel))))))
       (vl-cmdf ".Chprop" ss1 "" "layer" x ""))
           );cond end
  (setvar "cmdecho" 1)
  (princ)
)

就是COND为什么不用能IF代替?

 楼主| 发表于 2008-7-12 20:56 | 显示全部楼层

为什么我改成这样就没有办法用了

(if (/= ss2 "")

      (vl-cmdf ".Chprop" ss1 "" "layer" ss2 ""))
      ((setq x (cdr (assoc 8 (entget (car(entsel))))))
       (vl-cmdf ".Chprop" ss1 "" "layer" x ""))
           );if end

发表于 2008-7-12 21:21 | 显示全部楼层
aytxq发表于2008-7-12 20:56:00为什么我改成这样就没有办法用了(if (/= ss2 \"\")       (vl-cmdf \".Chprop\" ss1 \"\" \"layer\" ss2 \"\"));if到这里就结束了      (i

发表于 2008-7-12 22:11 | 显示全部楼层
弱弱的问下

(if (/= ss2 "")...) 和

(if ss2 ...)

有什么  区别

发表于 2008-7-12 22:17 | 显示全部楼层

通常情况下,if 函数在测试结果不为 nil 的情况下,仅对一个 then 表达式进行求值。在本例中由于使用了 progn 函数,可以实现对两个表达式的求值:

(if (= a b)
  (progn
    (princ "\nA = B ")
    (setq a (+ a 10) b (- b 10))
  )
)
发表于 2008-7-12 22:46 | 显示全部楼层
muwind发表于2008-7-12 22:11:00弱弱的问下 (if (/= ss2 \"\")...) 和 ss2/=\"\",是空字符,但不是nil(if ss2 ...)  ss2不是nil是为T有什么  区别

getstring 与getint 在空输入时的返回值不一样,前者返回"",后者返回nil

发表于 2008-7-12 22:49 | 显示全部楼层
byghbcx发表于2008-7-12 22:46:00getstring 与getint 在空输入时的返回值不一样,前者返回\"\",后者返回nil

哦 原来如此,谢谢,我很少用这两个函数....

 楼主| 发表于 2008-7-13 09:14 | 显示全部楼层
aytxq发表于2008-7-12 20:56:00为什么我改成这样就没有办法用了(if (/= ss2 \"\")       (vl-cmdf \".Chprop\" ss1 \"\" \"layer\" ss2 \"\"))      ((setq x (cdr (asso

我的原意是想用IF通(/= ss2 "")来完成两个表达式之间的选择:

    (vl-cmdf ".Chprop" ss1 "" "layer" ss2 ""))

  和  

  ((setq x (cdr (assoc 8 (entget (car(entsel))))))
       (vl-cmdf ".Chprop" ss1 "" "layer" x ""))
可是不知道为什么不行,只好用COND了

你给的方法是用两个IF分别来完成两个表达式的求值.虽然解决了问题,却还是没有解决我的疑惑.还请你再给我说明一下吧.谢谢!

 楼主| 发表于 2008-7-13 09:15 | 显示全部楼层
不好意思.刚才那些话是对byghbcx.
发表于 2008-7-13 12:10 | 显示全部楼层

((setq x (cdr (assoc 8 (entget (car(entsel))))))
       (vl-cmdf ".Chprop" ss1 "" "layer" x ""))

前面加上progn

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-10 10:58 , Processed in 0.170765 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表