刚好学习到eval这个函数,练习用了一下。写了一个统计长度和块数量的小工具。很初级的东西。大佬们不要见笑。
- ;-------------------------------------------------------------------------------------------------
- ;长度统计,块数量统计
- (defun c:tjcd (/ e filter i s ss totallength)
- (while (not (setq e (car (entsel)))))
- (setq filter (mapcar '(lambda (x) (list 'assoc x '(entget e))) (list 0 2 8))
- filter (mapcar 'eval filter)
- filter (vl-remove-if 'not filter)
- )
- (setq ss (ssget "X" filter)
- i -1
- totalLength 0
- )
- (sssetfirst nil ss)
- (cond
- ((wcmatch (cdr (assoc 0 filter)) "*LINE")
- (while (and (< (setq i (1+ i)) (sslength ss)) (setq s (ssname ss i)))
- (setq totalLength (+ (vla-get-Length (vlax-ename->vla-object s)) totalLength))
- )
- (princ (strcat "总长度为:" (rtos (/ totalLength 1000.) 2 2) "米"))
- (princ)
- )
- ((wcmatch (cdr (assoc 0 filter)) "INSERT")
- (princ (strcat "找到:" (rtos (sslength ss) 2 0) "个"))
- (princ)
- )
- )
- )
|