Lisp lệnh SHBV trong chủ đề “Lisp đánh số thứ tự bản vẽ tự động?”
OK, mình update giúp bạn đây, hy vọng bạn vừa ý
;; free lisp from cadviet.com : ketxu update from @Tue_NV (defun c:shbv(/ dau tong po po1 ent i pre sotong) (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 (getpoint (strcat "\n Cho diem chen cua so: " (if (< dau 10) (strcat pre "0" (itoa dau)) (itoa dau)) "/" sotong))) (wtxt (strcat (if (< dau 10) (strcat pre "0" (itoa dau)) (itoa dau)) "/" sotong) po) (Repeat (- tong dau) (setq po1 (getpoint po (strcat "\n Cho diem chen cua so: " (if (< (+ dau i) 10) (strcat pre "0" (itoa (+ dau i))) (itoa (+ dau i))) "/" sotong))) (command "copy" "L" "" po po1) (setq ent (entget(entlast))) (setq ent (subst (cons 1 (strcat (if (< (+ dau i) 10) (strcat pre "0" (itoa (+ dau i))) (itoa (+ dau i))) "/" sotong)) (assoc 1 ent) ent)) (entmod ent) (setq i (1+ i)) (setq po po1) ) (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))))
Lisp rất hay, nhưng đến phần " cho điểm chèn của số" mình muốn click thay số vào text có sẵn được không??.Nhờ bác sửa dùm. Thanks cả nhà.
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 159943_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 159943_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)
(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 (getpoint
(strcat "\n Cho diem chen cua so: " (if (< dau 10) (strcat pre "0" (itoa dau)) (itoa dau)) "/" sotong)))
(wtxt (strcat (if (< dau 10) (strcat pre "0" (itoa dau)) (itoa dau)) "/" sotong) po)
(Repeat (- tong dau)
(setq po1 (getpoint po
(strcat "\n Cho diem chen cua so: " (if (< (+ dau i) 10) (strcat pre "0" (itoa (+ dau i))) (itoa (+ dau i))) "/" sotong)))
(command "copy" "L" "" po po1)
(setq ent (entget(entlast)))
(setq ent
(subst
(cons 1 (strcat (if (< (+ dau i) 10) (strcat pre "0" (itoa (+ dau i))) (itoa (+ dau i))) "/" sotong)) (assoc 1 ent) ent))
(entmod ent)
(setq i (1+ i))
(setq po po1)
)
(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 #159943 để đọc hướng dẫn và trao đổi thêm.