Lisp lệnh TC TD trong chủ đề “edit nhanh 1 nhóm text trong cad”
dùng cách Find and Replace không khả thi, và co bất cập, vì như vậy chỉ thay thế tất cả các ký tự "10" thành "32a150"
===> chưa giải quyết được vấn đề.
Nếu bản vẽ của bạn chỉ có 1 loại thép 10-32a150, bạn có thể ẩn hết các đương kích thước đi, rồi copy text theo lệnh TC
===> chưa giải quyết được vấn đề.
Nếu bản vẽ của bạn chỉ có 1 loại thép 10-32a150, bạn có thể ẩn hết các đương kích thước đi, rồi copy text theo lệnh TC
- Tải lisp
- 90765_tc_td.lsp
Cách dùng
- Tải tệp 90765_tc_td.lsp về máy.
- Trong AutoCAD gõ lệnh APPLOAD, chọn tệp vừa tải rồi bấm Load. Cũng có thể kéo thả tệp .lsp vào cửa sổ bản vẽ.
- Gõ lệnh TC TD để chạy lisp.
Mã nguồn 90765_tc_td.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/18049-edit-nhanh-1-nh%C3%B3m-text-trong-cad/?tab=comments#comment-90765
(defun copy-add-text-content (mode / err oer sta res sel mtx dim chc chg
hig sor rdw dec temp
sou data)
;
(defun err(s)
(if (and (/= s "Function cancelled")(/= s "quit / exit abort"))
(princ (strcat "\n--->> Error: " s))
)
(res)
)
;
(defun res()
(if hig (setvar "HighLight" hig))
(if sor (setvar "Sortents" sor))
(if pst (setvar "Pickstyle" pst))
(if rdw (chc 0))
(command "_.Undo" "_End")
(setq *error* oer)
(setvar "Cmdecho" 1)
(princ)
)
;
(defun sta()
(setq oer *error*
*error* err
hig (getvar "HighLight")
sor (getvar "Sortents")
pst (getvar "Pickstyle")
dec (getvar "Dimdec")
)
(setvar "Cmdecho" 0)
(command "_.Undo" "_Group")
(setvar "HighLight" 1)
(setvar "Sortents" 1)
(setvar "Pickstyle" 0)
(graphscr)
)
;
(defun sel(/ loop lis typ intro)
(if (null del-mode)(setq del-mode "0"))
(if (null mat-mode)(setq mat-mode "0"))
(setq loop T
lis '("TEXT" "MTEXT" "DIMENSION" "ARCALIGNEDTEXT")
)
(if (= mode 0)
(setq intro "\nSelect copy source text ")
(setq intro "\nSelect additon source text ")
)
(while loop
(initget "Exit Delete Match MD DM")
;(setq del T);;;
(setq sou (entsel (strcat intro "[Delete source("del-mode")/Match properties("mat-mode")]: ")))
(cond
((= sou "Exit")(exit))
((null sou)(exit))
((= sou "Delete")
(if (= del-mode "0")
(setq del-mode "1")
(setq del-mode "0")
)
)
((= sou "Match")
(if (= mat-mode "0")
(setq mat-mode "1")
(setq mat-mode "0")
)
)
((or (= sou "MD")(= sou "DM"))
(progn
(if (= del-mode "0")
(setq del-mode "1")
(setq del-mode "0")
)
(if (= mat-mode "0")
(setq mat-mode "1")
(setq mat-mode "0")
)
)
)
((progn
(setq data (entget (car sou))
typ (cdr (assoc 0 data))
)
(if (not (member typ lis))
(princ "Invalid selection.")
(progn
(setq temp (assoc 1 data)
loop nil
)
(cond
((= typ "MTEXT")(mtx))
((= typ "DIMENSION")(dim))
)
)
); if end
))
); cond end
)
(chc 1)
(setq rdw T)
)
;
(defun mtx(/ con test)
(setq con (cdr temp)
test (substr con 1 1)
)
(if (= test "\\")(setq temp (cons 1 (substr con 5))))
)
;
(defun dim(/ con)
(setq con (cdr temp))
(if (or (= con "")(= con "<>"))
(setq temp (cons 1 (rtos (cdr (assoc 42 data)) 2 dec)))
)
)
;
(defun chc(mode / col)
(cond
((and (= del-mode "1") (= mat-mode "0"))(setq col "230"))
((and (= del-mode "0") (= mat-mode "1"))(setq col "110"))
((and (= del-mode "1") (= mat-mode "1"))(setq col "30"))
((setq col "140"))
)
(if (= mode 0)
(progn
(command "_.Chprop" sou "" "_Color" "BYLAYER" "")
(redraw (car sou) 4)
)
(progn
(command "_.Chprop" sou "" "_Color" col "")
(redraw (car sou) 3)
)
)
)
;
(defun chg(/ ss inc data-)
(if (= mode 0)
(princ "\nSelect destiantion texts to change: ")
(princ "\nSelect destiantion texts to add: ")
)
(setq ss (ssget '((-4 . "<OR")
(0 . "TEXT")(0 . "MTEXT")(0 . "DIMENSION")(0 . "ARCALIGNEDTEXT")
(-4 . "OR>")
)))
(if (null ss)(exit))
(setq inc 0)
(repeat (sslength ss)
(setq data- (entget (ssname ss inc))
inc (1+ inc))
(if (= mode 1)
(setq temp (cons 1 (strcat (cdr (assoc 1 data-)) "x" (cdr temp))))
)
(entmod (subst temp (assoc 1 data-) data-))
)
(if (= mat-mode "1")
(progn
(if rdw (chc 0))
(command "_.MatchProp" sou ss "")
)
)
(if (= del-mode "1")
(progn
(entdel (car sou))
(setq rdw nil)
)
)
)
;
(sta)
(sel)
(chg)
(res)
)
(defun c:TC()(copy-add-text-content 0))
(defun c:TD()(copy-add-text-content 1))
(princ)Thảo luận gốc
Lisp được chia sẻ trong chủ đề edit nhanh 1 nhóm text trong cad. Xem đúng bài viết #90765 để đọc hướng dẫn và trao đổi thêm.