本帖最后由 林霄云 于 2021-11-25 17:56 编辑
行情下行,修改增加,批量修改块名,避免块重名出错。- (defun c:brns( / bnlist bn t1 t2 x i)
- ;desiged by 林霄云 2021年11月23日
- ;批量改块名
- (setq bnlist '()) ;待修改块名列表
- (setq bn (tblnext "block" T)) ;If this argument is present and is not nil, the symbol table is rewound and the first entry in it is retrieved.
- (while (setq bn (tblnext "block"))
- (if (and (wcmatch (cdr (assoc 2 bn)) "[~*$_]*") (< (cdr (assoc 70 bn)) 4)) ;70组码,确定内部块还是外部参照
- ;取首字母不等于*$_,调整出特殊字符如[*$_]
- (setq bnlist (cons (cdr (assoc 2 bn)) bnlist));列表肯定是不重名的
- );if
- );while
- ;(setq bnlist (reverse bnlist)) ;确保内部块在前面,当排除外部参照时,次序不需要
- (setq t1 (rtos (getvar "cdate") 2 6) i 0) ;"20211123.114254"
- (foreach x bnlist
- (setq t2 (strcat x "_" t1))
- (command "rename" "b" x t2)
- (setq i (1+ i))
- (princ (strcat (itoa i) " :" x "\n"))
- ;(if (= 0 (rem i 5)) (princ "\n"))
- );foreach
- (princ (strcat "总共重命名" (itoa i) "个块!" "\n"))
- (princ)
- )
代码中,在批量修改中,排除了首字母为*$_的块 (wcmatch (cdr (assoc 2 bn)) "[~*$_]*")以及外部参照(< (cdr (assoc 70 bn)) 4)) ,批量修改块名为附加一个时间后缀(setq t1 (rtos (getvar "cdate") 2 6) i 0),不提供交互。批量修改时,交互的意义不大。
|