本帖最后由 77077 于 2014-10-16 22:40 编辑
新手上路,求大师帮忙优化~~~
- ;;; 属性字与单行文字互转
- (defun c:tt (/ ss1 n m str)
- (setq ss1 (mj:ss->list (ssget '((0 . "ATTDEF,TEXT"))))
- n 0
- m 0
- )
- (foreach ent ss1
- (cond
- ((= "ATTDEF" (cdr (assoc 0 (entget ent))))
- (setq n (1+ n))
- (att2txt ent)
- )
- ((= "TEXT" (cdr (assoc 0 (entget ent))))
- (setq m (1+ m))
- (txt2att ent)
- )
- )
- )
- (setq str (strcat "转化完成,共转化出<" (rtos n 2 0) ">个文字和<" (rtos m 2 0) ">个属性字"))
- (princ str)
- (princ)
- )
- ;;; 选择集转图元列表
- (defun mj:ss->list (ss1 / is-ename ss)
- (defun is-ename (arg)
- (equal (type arg) 'ename)
- )
- (vl-remove-if-not 'is-ename (mapcar
- 'cadr
- (ssnamex ss1)
- )
- )
- )
- ;;; 属性转文本
- (defun att2txt (ent / entdxf newdxf malst tem)
- (setq entdxf (entget ent)
- newdxf (list (cons 0 "text") (cons 1 (cdr (assoc 2 entdxf))))
- malst (list 7 8 10 11 39 40 41 50 51 62 71 72 73)
- )
- (foreach mai malst
- (setq tem (assoc mai entdxf))
- (if (/= tem nil)
- (setq newdxf (append
- newdxf
- (list (assoc mai entdxf))
- )
- )
- )
- )
- (entdel ent)
- (entmake newdxf)
- )
- ;;; 文本转属性
- (defun txt2att (ent / entdxf newdxf malst tem)
- (setq entdxf (entget ent)
- newdxf '((0 . "ATTDEF"))
- newdxf (append
- newdxf
- (list
- (cons 1 (cdr (assoc 1 entdxf)))
- (cons 2 (cdr (assoc 1 entdxf)))
- (cons 3 (cdr (assoc 1 entdxf))
- (cons 70 0)
- )
- )
- malst (list 7 8 10 11 39 40 41 50 51 62 71 72 73)
- )
- (foreach mai malst
- (setq tem (assoc mai entdxf))
- (if (/= tem nil)
- (setq newdxf (append
- newdxf
- (list (assoc mai entdxf))
- )
- )
- )
- )
- (entdel ent)
- (entmake newdxf)
- )
|