明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2685|回复: 3

cond用法

[复制链接]
发表于 2012-2-20 16:23:21 | 显示全部楼层 |阅读模式
  1. 求cond用法,如以下程序,用监视窗口可以得到 (cdr (assoc 1 (entget (ssname ssfunc 1))))的值,输入txt11 就变成nil,是不是cond不支持很多句子。以下程序想实现选中的文本组合起来列在一行,因为选中的文本有三个情况,一个文本,两个和三个。谢谢。

  2. (defun C:kl ()
  3.   (setq p1 (getpoint))
  4.   (setq p2 (getpoint))

  5.   (setq  ssfunc (ssget "w"
  6.           p1
  7.           p2
  8.           '((0 . "text,mtext")
  9.       (-4 . "<not")
  10.       (1 . "*[0-9]*")
  11.       (-4 . "not>")
  12.            )
  13.          )
  14.   )
  15. (setq a (sslength ssfunc))
  16.   (setq b(type a))
  17.   ;;below-test
  18.   (cond
  19.    
  20.     (= (sslength ssfunc) 2)
  21.     ((setq txt11 (cdr (assoc 1 (entget (ssname ssfunc 1)))))
  22.      (setq txt12 (cdr (assoc 1 (entget (ssname ssfunc 2)))))
  23.      (setq txt1 (strcat txt11 "]" txt12))
  24.     )

  25.     (= (sslength ssfunc) 3)
  26.     ((setq txt11 (cdr (assoc 1 (entget (ssname ssfunc 1)))))
  27.      (setq txt12 (cdr (assoc 1 (entget (ssname ssfunc 2)))))
  28.      (setq txt13 (cdr (assoc 1 (entget (ssname ssfunc 3)))))
  29.      (setq txt1 (strcat txt11 "]" txt12 "]" txt13))
  30.     )
  31.     (t
  32.      (setq txt1 (cdr (assoc 1 (entget (ssname ssfunc 1))))))
  33.     )
  34.     (print txt1)
  35.   )

发表于 2012-2-20 17:18:09 | 显示全部楼层
Try:

  1. (cond
  2.     ((= (sslength ssfunc) 2)
  3.      (setq txt11 (cdr (assoc 1 (entget (ssname ssfunc 1)))))
  4.      (setq txt12 (cdr (assoc 1 (entget (ssname ssfunc 2)))))
  5.      (setq txt1 (strcat txt11 "]" txt12))
  6.     )
  7.     ((= (sslength ssfunc) 3)
  8.      (setq txt11 (cdr (assoc 1 (entget (ssname ssfunc 1)))))
  9.      (setq txt12 (cdr (assoc 1 (entget (ssname ssfunc 2)))))
  10.      (setq txt13 (cdr (assoc 1 (entget (ssname ssfunc 3)))))
  11.      (setq txt1 (strcat txt11 "]" txt12 "]" txt13))
  12.     )
  13.     (t
  14.      (setq txt1 (cdr (assoc 1 (entget (ssname ssfunc 1)))))
  15.     )
  16.    )
 楼主| 发表于 2012-2-21 14:43:48 | 显示全部楼层
Andyhon 发表于 2012-2-20 17:18
Try:

成功了,谢谢,我太粗心了,竟然把括号给丢了,还有老是忘了ssname 是从0开始的
发表于 2012-2-21 15:16:33 | 显示全部楼层
本帖最后由 Andyhon 于 2012-2-21 15:17 编辑

套用函數...

  1. ;|
  2. General GET{ key(s) list(s) } function
  3. Created (1995) by Vladimir Nesterovsky
  4. e-mail me for any questions or comments
  5.       at [url=mailto:vnestr@netvision.net.il]vnestr@netvision.net.il[/url]
  6. YOU MAY USE THIS FUNCTION AS IT IS FOR ANY PURPOSE
  7. AT YOUR OWN RISK IF YOU RETAIN THIS NOTICE COMPLETE
  8. AND UNALTERED. NO WARRANTIES GIVEN WHATSOEVER.
  9. |;
  10. (defun get (k l)
  11.   ;; GET KEY(s) FROM LIST(s)
  12.   (if (atom (caar l))
  13.     ;; l is ASSOC'able list
  14.     (cond ;; use this l!
  15.           ((atom k)
  16.            ;; k is a key
  17.            (cdr (Assoc k l))
  18.           )
  19.           ((and (cdr k) (atom (cdr k)))
  20.            ;; '(0 . 8) -->> ("layer" . "Entity")
  21.            (cons (get (car k) l) (cdr (assoc (cdr k) l)))
  22.           )
  23.           (T
  24.            ;; k is a list of something - get inside
  25.            (mapcar (function (lambda (subk) (get subk l))) k)
  26.           )
  27.     )
  28.     ;; else - get inside list
  29.     (mapcar (function (lambda (subl) (get k subl))) l)
  30.   )
  31. )
  32. (defun sel2lst (sel / n l)
  33.   (cond
  34.     ((= (type sel) 'ENAME) (list sel))
  35.     (T
  36.      (repeat (setq n (sslength sel))
  37.        (setq n (1- n)
  38.              l (cons (ssname sel n) l)
  39.        )
  40.      )
  41.     )
  42.   )
  43. )
  44. ;;; ===================================
  45. (defun strlcatR (lst / a b)
  46.   (setq a (car lst)
  47.         b (cdr lst)
  48.   )
  49.   (if b
  50.     (strcat a "]" (strlcatR b))
  51.     a
  52.   )
  53. )
  54. ;;; ====================================
  55. (setq ssfunc (ssget
  56.                '((0 . "text,mtext")
  57.                  (-4 . "<not")
  58.                  (1 . "*[0-9]*")
  59.                  (-4 . "not>")
  60.                 )
  61.              )
  62. )
  63. (strlcatR (get 1 (mapcar 'entget (sel2lst ssfunc))))

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

本版积分规则

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

GMT+8, 2025-6-9 04:05 , Processed in 0.148495 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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