Jump to content

Lisp lệnh NHAPLENH trong chủ đề “Viết lisp theo yêu cầu [phần 2]”


Em dùng Lisp này thử xem nhé :

Đường Link mà svba gửi ở bài viết số 242 bị lỗi không down load được. Em xem lại đường Link 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

  1. Chép mã nguồn, lưu thành tệp 74934_nhaplenh.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 NHAPLENH để chạy lisp.

Mã nguồn 74934_nhaplenh.lsp (trích từ bài viết gốc)

(defun c:nhaplenh(/ oldim ans tto hto so ang delta tp so cao p)
(setq oldim (getvar "Dimzin"))
(setvar "Dimzin" 0)
(initget "T H")
(setq ans (getkword "\n Nhap tien to hoac hau to  :"))
(if (= ans "T") 
  (progn
   (if (not ttoo) (setq ttoo " "))
   (setq tto (getstring (strcat "\n Nhap tien to  :")))
   (if (not tto) (setq tto ttoo) (setq ttoo tto))
  )
)

(if (= ans "H") 
  (progn
   (if (not htoo) (setq htoo " "))
   (setq hto (getstring (strcat "\n Nhap hau to  :")))
   (if (not hto) (setq hto htoo) (setq htoo hto))
  )
)

(if (not soo) (setq soo 1))
(setq so (getreal (strcat "\n Nhap so bat dau  :")))
(if (not so) (setq so soo) (setq soo so))


(if (not deltao) (setq deltao 1))
(setq delta (getreal (strcat "\gia so  :")))
(if (not delta) (setq delta deltao) (setq deltao delta))

(if (not tpo) (setq tpo 0))
(setq tp (getint (strcat "\n So chu so thap phan  :")))
(if (not tp) (setq tp tpo) (setq tpo tp))
(setq cao (getdist "\n Chon chieu cao Text :"))

(if (= ans "T")
(progn
(while (setq p (getpoint "\n Chon diem dat Text :"))
(if (not ango) (setq ango 0))
(setq ang (getangle (strcat "\n Chon goc quay cua Text  :")))
(if (not ang) (setq ang ango) (setq ango ang))
(wtxt (strcat tto (rtos so 2 tp)) p ang cao)
(setq so (+ so delta))
);while
);progn

(progn
(while (setq p (getpoint "\n Chon diem dat Text :"))

(if (not ango) (setq ango 0))
(setq ang (getangle (strcat "\n Chon goc quay cua Text  :")))
(if (not ang) (setq ang ango) (setq ango ang))

(wtxt (strcat (rtos so 2 tp) hto) p ang cao)
(setq so (+ so delta))
);while
);progn
);if

(setvar "Dimzin" oldim)
(princ)
)
;
(defun wtxt (txt p ang h / sty)
(setq sty (getvar "textstyle"))
(entmake (list (cons 0 "TEXT") (cons 7 sty) 
(cons 1 txt) (cons 10 p) (cons 11 p) 
(cons 72 0) (cons 73 1) (cons 50 ang) 
(cons 40 h) (cons 41 1))
)
)

Thảo luận gốc

Lisp được chia sẻ trong chủ đề Viết lisp theo yêu cầu [phần 2]. Xem đúng bài viết #74934 để đọc hướng dẫn và trao đổi thêm.

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