Xin lisp cắt ký tự trong text cad
Dung thử code này xem :
(defun c:trt (/ key pos k ss te text len kq) (initget 1 "Left Right") (setq key (getkword "\n<L:Left> <R:Right> ")) (initget 7) (setq pos (getint "\nNhap 1 so nguyen : ")) (prompt "\n Chon cac chu de trim : ")(while (null (setq SS (ssget (list (cons 0 "Text"))))) (princ "\nChua chon duoc !")) (setq k 0) (repeat (sslength SS) (setq te (entget (ssname SS k))) (setq text (cdr (assoc 1 te))) (setq len (strlen text)) (if (< pos len) (progn (if (eq key "Right") (setq kq (substr text 1 (- (strlen text) pos))) (setq kq (substr text (+ pos 1)))) (entmod (setq te (subst (cons 1 kq) (assoc 1 te) te))))) (setq k (1+ k))) (princ))
- Tải lisp
- 305281_trt.lsp
Cách dùng
- Tải tệp 305281_trt.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 TRT để chạy lisp.
Mã nguồn 305281_trt.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/107424-y%C3%AAu-c%E1%BA%A7u-xin-lisp-c%E1%BA%AFt-k%C3%BD-t%E1%BB%B1-trong-text-cad/
(defun c:trt (/ key pos k ss te text len kq)
(initget 1 "Left Right") (setq key (getkword "\n<L:Left> <R:Right> "))
(initget 7) (setq pos (getint "\nNhap 1 so nguyen : "))
(prompt "\n Chon cac chu de trim : ")(while (null (setq SS (ssget (list (cons 0 "Text"))))) (princ "\nChua chon duoc !"))
(setq k 0)
(repeat (sslength SS)
(setq te (entget (ssname SS k))) (setq text (cdr (assoc 1 te))) (setq len (strlen text))
(if (< pos len)
(progn
(if (eq key "Right") (setq kq (substr text 1 (- (strlen text) pos))) (setq kq (substr text (+ pos 1))))
(entmod (setq te (subst (cons 1 kq) (assoc 1 te) te)))))
(setq k (1+ k)))
(princ))Thảo luận gốc
Lisp được chia sẻ trong chủ đề [Yêu cầu] Xin lisp cắt ký tự trong text cad. Xem đúng bài viết #305281 để đọc hướng dẫn và trao đổi thêm.