本帖最后由 自贡黄明儒 于 2013-2-26 09:18 编辑
我还没有发现它的用处,不过觉得很意思,所以改写了一下- ;;自贡黄明儒
- ;;调出选择集
- (defun c:ChooseSS (/ LIS SSNAM X)
- ;;(xzss 选择集名称),返回选择集
- (defun xzss (SSNam / N1 RESULT SS1)
- (setq result (VL-CATCH-ALL-APPLY 'vlax-ldata-get (list "tykm" SSNam)))
- (if (VL-CATCH-ALL-ERROR-P result)
- nil
- (progn
- (setq ss1 (ssadd))
- (repeat (length result)
- (setq n1 (car result))
- (setq result (cdr result))
- (ssadd (handent n1) ss1)
- )
- )
- )
- (sssetfirst nil ss1)
- )
- (if (setq lis (vlax-ldata-list "tykm"))
- (progn (princ (strcat "\n 已经存在选择集 "
- (apply 'strcat (mapcar '(lambda (x) (strcat (car x) ",")) lis))
- )
- )
- ;;(initget 7)
- (setq SSNam (getstring "\n 选择集名称: "))
- (VL-CATCH-ALL-APPLY 'xzss (list SSNam))
- )
- )
- (princ)
- )
- ;;删除选择
- (defun c:DelSS (/ LIS SSNAM X)
- ;;(initget 7)
- (if (setq lis (vlax-ldata-list "tykm"))
- (progn (princ (strcat "\n 已经存在选择集 "
- (apply 'strcat (mapcar '(lambda (x) (strcat (car x) ",")) lis))
- )
- )
- (setq SSNam (getstring "\n 选择集名称: "))
- (VL-CATCH-ALL-APPLY 'vlax-ldata-delete (list "tykm" SSNam))
- )
- )
- (princ)
- )
- ;;选择集成员句柄写入词典,随图一起保存
- (defun c:CreateSS (/ LIS LISTXZ N SSNAM X en SS)
- (if (setq lis (vlax-ldata-list "tykm"))
- (princ (strcat "\n 已经存在选择集 "
- (BAtte:lst->str (mapcar '(lambda (x) (car x)) lis) ",")
- )
- )
- )
- ;;(initget 7)
- (if (and (setq SSNam (getstring "\n 选择集名称: "))
- (setq SS (ssget))
- )
- (progn
- (repeat (setq n (sslength SS))
- (setq en (ssname SS (setq n (1- n))))
- (setq listxz (append listxz (list (cdr (assoc 5 (entget en))))))
- )
- (VL-CATCH-ALL-APPLY 'vlax-ldata-put (list "tykm" SSNam listxz))
- )
- )
- (princ)
- )
- ;;(BAtte:lst->str (list "A" "B") ","),返回"A,B"
- (defun BAtte:lst->str (lst del)
- (if (cdr lst)
- (strcat (car lst) del (BAtte:lst->str (cdr lst) del))
- (car lst)
- )
- )
- ;;(BAtte:str->lst "A,B" ",")返回("A" "B")
- (defun BAtte:str->lst (str del / pos)
- (if (setq pos (vl-string-search del str))
- (cons (substr str 1 pos)
- (BAtte:str->lst (substr str (+ pos 1 (strlen del))) del)
- )
- (list str)
- )
- )
|