本帖最后由 vectra 于 2013-7-10 08:29 编辑
先发代码,求优化注释说明以后再补充
- (defun ace-reg-appid (name /)
- (if (null (tblsearch "APPID" name))
- (regapp name)
- )
- )
- (defun ace-xdata-get (ename appid /)
- (if (= "*" appid)
- (cdr (assoc '-3 (entget ename (list appid))))
- (cdr (assoc appid (cdr (assoc '-3 (entget ename (list appid))))))
- )
- )
- (defun ace-xdata-set (ename appid data / code data-3 data-old data-app)
- (setq code (entget ename (list "*"))
- data-3 (assoc '-3 code)
- data-app (append (list appid) data)
- )
- (if (null data-3)
- ;; 不存在扩展数据时添加
- (setq code (append code (list (list -3 data-app))))
- (if (setq data-old (assoc appid (cdr data-3)))
- ;; 扩展数据中已存在APPID项, 仅在内容不同时才进行替换
- (if (not (equal data-app data-old))
- (setq code (subst (subst data-app data-old data-3) data-3 code))
- )
- ;; 在扩展数据中加入新项
- (setq code (subst (append data-3 (list data-app)) data-3 code))
- )
- )
- (entmod code)
- )
- (defun ace-xdata-remove (ename appid / code data-3 data-old)
- (setq code (entget ename (list "*"))
- data-3 (assoc '-3 code)
- )
- (if (and data-3 (setq data-old (assoc appid (cdr data-3))))
- (progn
- (setq
- code (subst (subst (list appid) data-old data-3) data-3 code)
- )
- (entmod code)
- )
- )
- )
Sample
_$ (ace-reg-appid "T1")
"T1"
_$ (ace-reg-appid "T2")
"T2"
_$ (ace-xdata-set (handent "1BB") "T1" '((1000 . "Text")(1000 . "More Text...")))
...
_$ (ace-xdata-get (handent "1BB") "T1")
((1000 . "Text") (1000 . "More Text..."))
_$ (ace-xdata-set (handent "1BB") "T2" '((1070 . 10)))
...
_$ (ace-xdata-get (handent "1BB") "T2")
((1070 . 10))
_$ (ace-xdata-get (handent "1BB") "*")
(("T1" (1000 . "Text") (1000 . "More Text...")) ("T2" (1070 . 10)))
_$ (ace-xdata-set (handent "1BB") "T2" '((1070 . 20)(1070 . 30)))
...
_$ (ace-xdata-get (handent "1BB") "T2")
((1070 . 20) (1070 . 30))
_$ (ace-xdata-remove (handent "1BB") "T2")
...
_$ (ace-xdata-get (handent "1BB") "*")
(("T1" (1000 . "Text") (1000 . "More Text...")))
|