Lisp cộng thêm hằng số K
Nhờ các member chỉnh sửa cho mình Lisp cộng thêm vào một dãy số đã có một hằng số K, mà khi chạy lệnh, lisp tự động nhớ con số mình vừa nhập, không phải nhập lại sau mỗi lần chạy lệnh.
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/10226-lisp-cong-text-toan-bo-ban-ve-them-1-hang-so/
(defun c:as()
(setq i 0 s1 0)
(setq n (getreal "\nnhap so bi tru hoac so de cong: "))
(prompt "\nchon cac so can sua ...")
(setq txt (ssget '((0 . "TEXT"))))
(repeat (sslength txt)
(setq txt_name (ssname txt i))
(setq txt_ent (entget txt_name))
(setq cont (cdr(assoc 1 txt_ent)))
(setq cont (atof cont))
(setq s (+ cont n))
(setq txt_ent (subst (cons 1 (rtos s)) (assoc 1 txt_ent) txt_ent))
(entmod txt_ent)
(setq i (+ i 1))
);repeat
);defun
;------------------------------------------------------
Thanks !
- Tải lisp
- 243770_as.lsp
Cách dùng
- Tải tệp 243770_as.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 AS để chạy lisp.
Mã nguồn 243770_as.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/74954-nh%E1%BB%9D-ch%E1%BB%89nh-s%E1%BB%ADa-lisp-c%E1%BB%99ng-th%C3%AAm-h%E1%BA%B1ng-s%E1%BB%91-k/
;; free lisp from cadviet.com;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/10226-lisp-cong-text-toan-bo-ban-ve-them-1-hang-so/(defun c:as()(setq i 0 s1 0)(setq n (getreal "\nnhap so bi tru hoac so de cong: "))(prompt "\nchon cac so can sua ...")(setq txt (ssget '((0 . "TEXT"))))(repeat (sslength txt)(setq txt_name (ssname txt i))(setq txt_ent (entget txt_name))(setq cont (cdr(assoc 1 txt_ent)))(setq cont (atof cont))(setq s (+ cont n))(setq txt_ent (subst (cons 1 (rtos s)) (assoc 1 txt_ent) txt_ent))(entmod txt_ent)(setq i (+ i 1)));repeat);defun;------------------------------------------------------
Thảo luận gốc
Lisp được chia sẻ trong chủ đề [Nhờ chỉnh sửa] Lisp cộng thêm hằng số K. Xem đúng bài viết #243770 để đọc hướng dẫn và trao đổi thêm.