Jump to content

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 này hay rồi nhưng nếu cách thức hoạt động dạng array như lisp dsbv của bác Tue_VN thì hay quá.

Mong các pro thêm phần này vào nữa.

P/S: phần số thì thay đổi theo cấp số cộng, còn phần chữ thì cố định, và tùy ý người sử dụng chọn. Vd: abc-01 hoặc xyz-01

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

  1. Chép mã nguồn, lưu thành tệp 194015_shbv.lsp.
  2. 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ẽ.
  3. Gõ lệnh SHBV để chạy lisp.

Mã nguồn 194015_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 #194015 để đọc hướng dẫn và trao đổi thêm.

Về Thư viện AutoLisp (trang 264)