Lisp lệnh TC TD trong chủ đề “Nhờ Chỉnh Sửa Lisp Replac Text”
Cảm ơn bác đã hồi âm, em muốn text đích là attribute. Mong bác ra tay giúp đỡ. Cảm ơn bác và anh em cộng đồng cadviet nhiều.
Hề hề hề,
Bạn dùng thủ cái này coi sao. Mình sửa lại một chút để có thể cả text nguồn và đích đều là các thuộc tính.
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/165503-nho-chinh-sua-lisp-replac-text/
;=========================================================================
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/index.php?showtopic=18049
(defun copy-add-text-content (mode / err oer sta res sel mtx dim chc chg
hig sor rdw dec temp a b
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 (nentsel (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")(0 . "INSERT")
(-4 . "OR>")
)))
(if (null ss)(exit))
(setq inc 0)
(repeat (sslength ss)
(setq data- (entget (ssname ss inc))
inc (1+ inc))
(setq a (ssname ss (1- inc)))
(if (= (cdr (assoc 0 data-)) "INSERT")
(progn
(alert "\n Doi tuong chon là block.")
(setq b (ssadd a))
(sssetfirst ss b)
(setq data- (entget (car (nentsel "\n Ban hay pick lai thuoc tinh can thay doi"))))
)
)
(if (= mode 1)
(setq temp (cons 1 (strcat (cdr (assoc 1 data-)) "x" (cdr temp))))
)
(entmod (subst temp (assoc 1 data-) data-))
(entupd a)
)
(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)
Tệp .lsp gốc không còn trên máy chủ. Hãy chép mã nguồn bên dưới (lấy từ bài viết gốc) vào một tệp văn bản, lưu với đuôi .lsp.
Cách dùng
- Chép mã nguồn, lưu thành tệp 406902_tc_td.lsp.
- 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 406902_tc_td.lsp (trích từ bài viết gốc)
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/165503-nho-chinh-sua-lisp-replac-text/
;=========================================================================
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/index.php?showtopic=18049
(defun copy-add-text-content (mode / err oer sta res sel mtx dim chc chg
hig sor rdw dec temp a b
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 (nentsel (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")(0 . "INSERT")
(-4 . "OR>")
)))
(if (null ss)(exit))
(setq inc 0)
(repeat (sslength ss)
(setq data- (entget (ssname ss inc))
inc (1+ inc))
(setq a (ssname ss (1- inc)))
(if (= (cdr (assoc 0 data-)) "INSERT")
(progn
(alert "\n Doi tuong chon là block.")
(setq b (ssadd a))
(sssetfirst ss b)
(setq data- (entget (car (nentsel "\n Ban hay pick lai thuoc tinh can thay doi"))))
)
)
(if (= mode 1)
(setq temp (cons 1 (strcat (cdr (assoc 1 data-)) "x" (cdr temp))))
)
(entmod (subst temp (assoc 1 data-) data-))
(entupd a)
)
(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ủ đề Nhờ Chỉnh Sửa Lisp Replac Text. Xem đúng bài viết #406902 để đọc hướng dẫn và trao đổi thêm.