Lisp lệnh SHBV trong chủ đề “Lisp đánh số thứ tự bản vẽ tự động?”
Hề hề hề,
Phải chăng bạn ấy muốn cái như thế này:
;; free lisp from cadviet.com : ketxu update from @Tue_NV (defun c:shbv(/ dau tong po po1 ent i pre sotong en en1) (command "undo" "be") (prompt "\n Danh so hieu ban ve dang n/m ") (setvar "cmdecho" 0) (setq pre "< KC, CN KT>: ") (wtxt pre '(0 0 0)) (command "ddedit" (entlast) "") (setq pre (cdr(assoc 1 (entget(entlast))))) ;(setq pre (strcat pre ": ")) (entdel (entlast)) (setq dau (getint "\n Danh so bat dau (n):")) (setq tong (getint "\n Danh so tong (m):") i 1) (if (< tong 10) (setq sotong (strcat "0" (itoa tong))) (setq sotong (itoa tong))) (setq po (cdr (assoc 11 (entget (car (setq en (entsel (strcat "\n Hay chon text can thay the boi " pre (if (< dau 10) (strcat "0" (itoa dau)) (itoa dau)) "/" sotong)))))))) ;;;;(getpoint (strcat "\n Cho diem chen cua so: " (if (< dau 10) (strcat pre "0" (itoa dau)) (itoa dau)) "/" sotong))) (command "erase" en "") (wtxt (strcat pre (if (< dau 10) (strcat "0" (itoa dau)) (itoa dau)) "/" sotong) po) (Repeat (- tong dau) (setq po1 (cdr (assoc 11 (entget (car (setq en1 (entsel (strcat "\n Hay chon text can thay the boi " pre (if (< (+ dau i) 10) (strcat "0" (itoa (+ dau i))) (itoa (+ dau i))) "/" sotong)))))))) ;;;(getpoint po (strcat "\n Cho diem chen cua so: " (if (< (+ dau i) 10) (strcat pre "0" (itoa (+ dau i))) (itoa (+ dau i))) "/" sotong))) (command "erase" en1 "") (command "copy" "L" "" po po1) (setq ent (entget(entlast))) (setq ent (subst (cons 1 (strcat pre (if (< (+ dau i) 10) (strcat "0" (itoa (+ dau i))) (itoa (+ dau i))) "/" sotong)) (assoc 1 ent) ent)) (entmod ent) (setq i (1+ i)) (setq po po1) ) (command "undo" "e") (princ) ) ; (defun wtxt(txt p / sty d h1 h2 wf h) ;;;Write txt on graphic screen at p (setq sty (getvar "textstyle") d (tblsearch "style" sty) h1 (cdr (assoc 40 d)) h2 (cdr (assoc 42 d)) wf (cdr (assoc 41 d))) (if (> h1 0) (setq h h1) (setq h h2)) (entmake (list (cons 0 "TEXT") (cons 7 sty) (cons 40 h) (cons 41 wf)(cons 72 4)(cons 11 p) (cons 1 txt) (cons 10 p))))
@Bác Tue_NV và Ketxu: Mạn phép sửa lại tí chút cái lisp của các bác cái chổ :
(wtxt (strcat (if (< dau 10) (strcat pre "0" (itoa dau)) (itoa dau)) "/" sotong) po)
Có nhẽ phải là:
(wtxt (strcat pre (if (< dau 10) (strcat "0" (itoa dau)) (itoa dau)) "/" sotong) po)
mới đúng ạ.
Rất cảm ơn 2 bạn đã hiểu đúng ý mình :D.
Không biết có phải tại máy mình không???, khi kick vào text có sẵn thì text mới bị nhảy lung tung và dồn lại 1 cục...
Nhờ bạn kiểm tra lại dùm.
Cảm ơn nhiều nhiều.
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 161668_shbv.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 SHBV để chạy lisp.
Mã nguồn 161668_shbv.lsp (trích từ bài viết gốc)
;; free lisp from cadviet.com : ketxu update from @Tue_NV
(defun c:shbv(/ dau tong po po1 ent i pre sotong en en1)
(command "undo" "be")
(prompt "\n Danh so hieu ban ve dang n/m ")
(setvar "cmdecho" 0)
(setq pre "< KC, CN KT>: ")
(wtxt pre '(0 0 0))
(command "ddedit" (entlast) "")
(setq pre (cdr(assoc 1 (entget(entlast)))))
;(setq pre (strcat pre ": "))
(entdel (entlast))
(setq dau (getint "\n Danh so bat dau (n):"))
(setq tong (getint "\n Danh so tong (m):") i 1)
(if (< tong 10) (setq sotong (strcat "0" (itoa tong))) (setq sotong (itoa tong)))
(setq po (cdr (assoc 11 (entget (car (setq en (entsel
(strcat "\n Hay chon text can thay the boi " pre (if (< dau 10) (strcat "0" (itoa dau)) (itoa dau)) "/" sotong))))))))
;;;;(getpoint (strcat "\n Cho diem chen cua so: " (if (< dau 10) (strcat pre "0" (itoa dau)) (itoa dau)) "/" sotong)))
(command "erase" en "")
(wtxt (strcat pre (if (< dau 10) (strcat "0" (itoa dau)) (itoa dau)) "/" sotong) po)
(Repeat (- tong dau)
(setq po1 (cdr (assoc 11 (entget (car (setq en1 (entsel
(strcat "\n Hay chon text can thay the boi " pre (if (< (+ dau i) 10) (strcat "0" (itoa (+ dau i))) (itoa (+ dau i))) "/" sotong))))))))
;;;(getpoint po (strcat "\n Cho diem chen cua so: " (if (< (+ dau i) 10) (strcat pre "0" (itoa (+ dau i))) (itoa (+ dau i))) "/" sotong)))
(command "erase" en1 "")
(command "copy" "L" "" po po1)
(setq ent (entget(entlast)))
(setq ent
(subst
(cons 1 (strcat pre (if (< (+ dau i) 10) (strcat "0" (itoa (+ dau i))) (itoa (+ dau i))) "/" sotong)) (assoc 1 ent) ent))
(entmod ent)
(setq i (1+ i))
(setq po po1)
)
(command "undo" "e")
(princ)
)
;
(defun wtxt(txt p / sty d h1 h2 wf h) ;;;Write txt on graphic screen at p
(setq sty (getvar "textstyle")
d (tblsearch "style" sty)
h1 (cdr (assoc 40 d))
h2 (cdr (assoc 42 d))
wf (cdr (assoc 41 d)))
(if (> h1 0) (setq h h1) (setq h h2))
(entmake (list (cons 0 "TEXT") (cons 7 sty) (cons 40 h) (cons 41 wf)(cons 72 4)(cons 11 p) (cons 1 txt) (cons 10 p))))Thảo luận gốc
Lisp được chia sẻ trong chủ đề Lisp đánh số thứ tự bản vẽ tự động?. Xem đúng bài viết #161668 để đọc hướng dẫn và trao đổi thêm.