- Lưu code sau vào file .lsp => sau đó vào autocad nhập lệnh APPLOAD với chế độ always để load lisp này vào.
- Để sử dụng, vui lòng nhập lệnh nosine_rnbl , hoặc bạn có thể đổi tên hàm thành chuỗi dễ nhớ hơn.
;; Rename block
(defun c:nosine_rnbl (/ find replace blocks blkName newname)
;; Input
(setq find (getstring "\nNhập tiền tố ban đầu (vd: EL_TE-): "))
(setq replace (getstring "\Nhập tiền tố sau khi thay thế (vd: ME_TE-): "))
;; Duyệt tất cả block definitions
(setq blocks (tblnext "BLOCK" T))
(while blocks
(setq blkName (cdr (assoc 2 blocks)))
;; Bỏ qua block ẩn hoặc xref
(if (and (/= (logand (cdr (assoc 70 blocks)) 1) 1)
(wcmatch blkName (strcat find "*")))
(progn
;; str_replace
(setq newname (vl-string-subst replace find blkName))
;; Gọi lệnh RENAME của autocad
(princ (strcat "\nRenaming: " blkName " -> " newname))
(command "_.RENAME" "Block" blkName newname)
)
)
;; next block
(setq blocks (tblnext "BLOCK"))
)
(princ "\nHoàn tất.")
(princ)
)
Bình luận