- 积分
- 36724
- 明经币
- 个
- 注册时间
- 2009-1-8
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2018-5-2 21:32:10
|
显示全部楼层
;; modify by edata 2018-5-2
;; 修改自动递增三位数前置0对齐;
;; 修改图块名为 "图框"
;; 修改图块属性名称为 "图号"
- ;;-----------------=={ AutoLabel Attributes }==---------------;;
- ;; ;;
- ;; Automatically labels a specific attribute in a set of ;;
- ;; blocks, renumbering if blocks are added, copied or ;;
- ;; erased. ;;
- ;;------------------------------------------------------------;;
- ;; Author: Lee Mac, Copyright ?2011 - www.lee-mac.com ;;
- ;;------------------------------------------------------------;;
- ;; Version 1.0 - 14-09-2011 ;;
- ;;------------------------------------------------------------;;
- ;;------------------------------------------------------------;;
- ;; Settings ;;
- ;;------------------------------------------------------------;;
- ;; [Note: Block names and Attribute Tags are *not* case-sensitive]
- ;; modify by edata 2018-5-2
- ;; 修改自动递增三位数前置0对齐;
- ;; 修改图块名为 "图框"
- ;; 修改图块属性名称为 "图号"
- (setq *blockname* "图框" ;; 修改需要自动递增的图块名称,如: "图框" ;;Name of Block to be Updated
- *blocktag* "图号" ;; 修改需要自动递增的图块属性名称,如: "图号" ;;Attribute Tag to be Updated
- )
- ;;------------------------------------------------------------;;
- ;; Main Program ;;
- ;;------------------------------------------------------------;;
- (defun ObjectReactorCallback:RenumberBlocks ( object reactor params )
- (setq *reactor* reactor)
- (vlr-command-reactor "temp" '((:vlr-commandended . CommandReactorCallback:RenumberBlocks)))
- (vlr-remove reactor)
- (princ)
- )
- ;;------------------------------------------------------------;;
- (defun CommandReactorCallback:RenumberBlocks ( reactor params / e f i l n s )
- (if reactor (vlr-remove reactor))
- (if
- (and
- (not *undoflag*)
- (setq s (ssget "_X" *filter*))
- )
- (progn
- (setq n 0)
- (repeat (setq i (sslength s))
- (if (eq *blockname*
- (AutoLabel:EffectiveName
- (setq o (vlax-ename->vla-object (setq e (ssname s (setq i (1- i))))))
- )
- )
- (progn
- (setq e (entnext e)
- l (entget e)
- f nil
- )
- (while (and (not f) (eq "ATTRIB" (cdr (assoc 0 l))))
- (if (eq *blocktag* (strcase (cdr (assoc 2 l))))
- (progn
- ;;添加前置零三位数对齐001,002,003...
- (setq f (entmod (subst (cons 1 (cond ((< (1+ n) 10)(strcat "00" (itoa (setq n (1+ n)))))
- ((< (1+ n) 100)(strcat "0" (itoa (setq n (1+ n)))))
- (t (itoa (setq n (1+ n)))))) (assoc 1 l) l)))
- )
- )
- (setq e (entnext e)
- l (entget e)
- )
- )
- (if (and *reactor* (not (member o (vlr-owners *reactor*))))
- (vlr-owner-add *reactor* o)
- )
- )
- )
- )
- )
- )
- (if *reactor*
- (progn (vlr-add *reactor*) (setq *reactor* nil))
- )
- (princ)
- )
- ;;------------------------------------------------------------;;
- (defun CommandReactorCallback:UndoCheck ( reactor params )
- (setq *undoflag* (wcmatch (strcase (car params)) "*U,*UNDO"))
- (princ)
- )
- ;;------------------------------------------------------------;;
- (defun CommandReactorCallback:BlockInserted ( reactor params / e l )
- (if
- (and
- (not *undoflag*)
- (wcmatch (strcase (car params)) "*I,*INSERT,*EXECUTETOOL")
- (setq e (entlast))
- (setq l (entget e))
- (eq "INSERT" (cdr (assoc 0 l)))
- (= 1 (cdr (assoc 66 l)))
- (eq *blockname* (AutoLabel:EffectiveName (vlax-ename->vla-object e)))
- )
- (AutoLabel:GetNewNumber e)
- )
- (princ)
- )
- ;;------------------------------------------------------------;;
- (defun AutoLabel:GetNewNumber ( ent / e f i l n r s )
- (if (setq s (ssget "_X" *filter*))
- (progn
- (setq n 0)
- (repeat (setq i (sslength s))
- (if (eq *blockname*
- (AutoLabel:Effectivename
- (vlax-ename->vla-object (ssname s (setq i (1+ i))))
- )
- )
- (setq n (1+ n))
- )
- )
- (setq e (entnext ent)
- l (entget e)
- )
- (while (and (not f) (eq "ATTRIB" (cdr (assoc 0 l))))
- (if (eq *blocktag* (strcase (cdr (assoc 2 l))))
- (progn
- (setq f (entmod (subst (cons 1 (cond ((< n 10)(strcat "00" (itoa n)))
- ((< n 100)(strcat "0" (itoa n)))
- (t (itoa n)))) (assoc 1 l) l)))
- )
- )
- (setq e (entnext e)
- l (entget e)
- )
- )
- (if
- (setq r
- (vl-some
- (function
- (lambda ( r ) (if (eq *reacdata* (vlr-data r)) r))
- )
- (cdar (vlr-reactors :vlr-object-reactor))
- )
- )
- (vlr-owner-add r (vlax-ename->vla-object ent))
- )
- )
- )
- (princ)
- )
- ;;------------------------------------------------------------;;
- (defun AutoLabel:EffectiveName ( obj )
- (strcase
- (if (vlax-property-available-p obj 'effectivename)
- (vla-get-effectivename obj)
- (vla-get-name obj)
- )
- )
- )
- ;;------------------------------------------------------------;;
- ;; Loading Expressions ;;
- ;;------------------------------------------------------------;;
- (vl-load-com)
- (
- (lambda ( / i s l o )
- (setq
- *blocktag* (strcase *blocktag*)
- *blockname* (strcase *blockname*)
- *reacdata* "AutoBlockLabel"
- *reactor* nil
- *undoflag* nil
- )
- (foreach r1 (vlr-reactors)
- (foreach r2 (cdr r1)
- (if (eq *reacdata* (vlr-data r2)) (vlr-remove r2))
- )
- )
- (if
- (setq s
- (ssget "_X"
- (setq *filter*
- (list
- '(0 . "INSERT")
- '(66 . 1)
- (cons 2 (strcat "`*U*," *blockname*))
- (cons 410 (getvar 'CTAB))
- )
- )
- )
- )
- (progn
- (repeat (setq i (sslength s))
- (if (eq *blockname*
- (AutoLabel:EffectiveName
- (setq o (vlax-ename->vla-object (ssname s (setq i (1- i)))))
- )
- )
- (setq l (cons o l))
- )
- )
- (CommandReactorCallback:RenumberBlocks nil nil)
- (vlr-object-reactor l *reacdata*
- (list
- (cons :vlr-erased 'ObjectReactorCallback:RenumberBlocks)
- (cons :vlr-copied 'ObjectReactorCallback:RenumberBlocks)
- (cons :vlr-unerased 'ObjectReactorCallback:RenumberBlocks)
- )
- )
- (vlr-command-reactor *reacdata*
- (list
- (cons :vlr-commandwillstart 'CommandReactorCallback:UndoCheck)
- (cons :vlr-commandended 'CommandReactorCallback:BlockInserted)
- )
- )
- )
- )
- )
- )
- (princ)
- ;;------------------------------------------------------------;;
- ;; End of File ;;
- ;;------------------------------------------------------------;;
|
|