Lisp lệnh 3 4 5 trong chủ đề “Cần gấp lisp tăng giá trị khi chọn”
Bạn xem lisp dồn số hiệu bản vẽ ở đây: https://www.cadviet.com/cadnews/content/view/22/34/
(defun myerror (s) (cond ((= s "quit / exit abort") (princ)) ((/= s "Function cancelled") (princ (strcat "\nError: " s))) ) (setvar "cmdecho" CMD) ; Restore saved modes (setvar "osmode" OSM) (setq *error* OLDERR) ; Restore old *error* handler (princ) ) (defun intro () (princ "\nCopyright by Nguyen Gia Dat ([email protected] - 0915169886)") ) (defun bocchu (ss1 c) (setq ob (entget (ssname ss1 c))) (setq ts (assoc 1 ob)) (setq a (cdr ts)) ) (defun sothanhchu (num) (rtos num 2 2)) (defun connumint (num) (rtos num 2 0)) (defun thaychu (Ob newstr) (setq txtstr (assoc 1 Ob)) (setq newstr (cons 1 newstr)) (entmod (subst newstr txtstr Ob)) ) (defun chonchu (dongnhac) (prompt dongnhac) (ssget '((-4 . "<OR") (0 . "text") (0 . "mtext") (-4 . "OR>")) ) ) (defun chon (str) (ssget '((cons (0 str))))) (defun bamchon (st) (entget (car (entsel st)))) (defun bocdt (ss1 c) (entget (ssname ss1 c))) ;;; Sua nhieu text (cong tru gia tri thuc) (defun c:3 () (command "undo" "mark") (intro) (setq ss1 (chonchu "\nChon text can cong them ...") ) (if (= Ostr nil) (setq Ostr "\nNhap gia tri tang them <>...: ") ) (while (= ss1 nil) (setq ss1 (chonchu "\nChon text can cong them ...") ) ) (setq i 0 num2 (getreal Ostr) sslen (sslength ss1) ) (if (/= num2 nil) (setq numadd num2 ) ) (if (/= numadd nil) (setq Ostr (strcat "\nNhap gia tri tang them <" (rtos numadd 2 2) "> : " ) ) ) (while (<= i (1- sslen)) (setq num1 (atof (bocchu ss1 i)) ) (setq num (+ num1 numadd)) (setq ob (bocdt ss1 i)) ;(if (< num 10) ; (setq st (strcat "0" (connumint num))) (setq st (sothanhchu num)) ; ) (thaychu ob st) (princ) (setq i (1+ i)) ) ) ;;; Sua nhieu text (cong tru gia tri nguyen) (defun c:4 () (intro) (command "undo" "mark") (setq ss1 (chonchu "\nChon text can cong them ...") ) (if (= Ostr nil) (setq Ostr "\nNhap gia tri tang them <>...: ") ) (while (= ss1 nil) (setq ss1 (chonchu "\nChon text can cong them ...") ) ) (setq i 0 num2 (getint Ostr) sslen (sslength ss1) ) (if (/= num2 nil) (setq numadd num2 ) ) (if (/= numadd nil) (setq Ostr (strcat "\nNhap gia tri tang them <" (rtos numadd 2 0) "> : " ) ) ) (while (<= i (1- sslen)) (setq num1 (atof (bocchu ss1 i)) ) (setq num (+ num1 numadd)) (setq ob (bocdt ss1 i)) (if (< num 10) (setq st (strcat "0" (connumint num))) (setq st (connumint num)) ) (thaychu ob st) (princ) (setq i (1+ i)) ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun c:5 () (intro) (command "undo" "mark") (setq ss1 (chonchu "\nChon text can cong them ...") ) (if (= Ostr nil) (setq Ostr "\nNhap gia tri tang them <>...: ") ) (while (= ss1 nil) (setq ss1 (chonchu "\nChon text can cong them ...") ) ) (setq i 0 num2 (getreal Ostr) sslen (sslength ss1) ) (if (/= num2 nil) (setq numadd num2 ) ) (if (/= numadd nil) (setq Ostr (strcat "\nNhap gia tri tang them <" (rtos numadd 2 2) "> : " ) ) ) (while (<= i (1- sslen)) (setq num1 (atof (bocchu ss1 i)) ) (setq num (+ num1 numadd)) (setq ob (bocdt ss1 i)) (if (> num 0) (setq st (strcat "+" (sothanhchu num))) (setq st (sothanhchu num)) ) (thaychu ob st) (princ) (setq i (1+ i)) ) )
Lệnh "3": tăng giảm nhiều số dưới dạng số thực
Lệnh "4": tăng giảm các số nguyên (dạng số thứ tự)
Lện "5": tăng giảm các số nguyên có chứa dấu (dạng cao độ)
Hy vọng giúp ích cho bạn
Chết thật! trong lúc em post bài thì bác Hoanh đã kịp trả lời trước rồi. Lisp của mình có thể kết hợp với các biện pháp chọn lọc đối tượng text - sẽ đem lại hiệu quả nhanh hơn (Tất nhiên ko thể so sánh với bộ công cụ trên của bác Hoành :mellow:
Thanks các bác nhiều lắm.Mình đã làm được rồi.
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 22277_3_4_5.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 3 4 5 để chạy lisp.
Mã nguồn 22277_3_4_5.lsp (trích từ bài viết gốc)
(defun myerror (s)
(cond
((= s "quit / exit abort") (princ))
((/= s "Function cancelled") (princ (strcat "\nError: " s)))
)
(setvar "cmdecho" CMD) ; Restore saved modes
(setvar "osmode" OSM)
(setq *error* OLDERR) ; Restore old *error* handler
(princ)
)
(defun intro ()
(princ "\nCopyright by Nguyen Gia Dat ([email protected] - 0915169886)")
)
(defun bocchu (ss1 c)
(setq ob (entget (ssname ss1 c)))
(setq ts (assoc 1 ob))
(setq a (cdr ts))
)
(defun sothanhchu (num) (rtos num 2 2))
(defun connumint (num) (rtos num 2 0))
(defun thaychu (Ob newstr)
(setq txtstr (assoc 1 Ob))
(setq newstr (cons 1 newstr))
(entmod (subst newstr txtstr Ob))
)
(defun chonchu (dongnhac)
(prompt dongnhac)
(ssget
'((-4 . "<OR") (0 . "text") (0 . "mtext") (-4 . "OR>"))
)
)
(defun chon (str) (ssget '((cons (0 str)))))
(defun bamchon (st) (entget (car (entsel st))))
(defun bocdt (ss1 c) (entget (ssname ss1 c)))
;;; Sua nhieu text (cong tru gia tri thuc)
(defun c:3 ()
(command "undo" "mark")
(intro)
(setq ss1 (chonchu "\nChon text can cong them ...")
)
(if (= Ostr nil)
(setq Ostr "\nNhap gia tri tang them <>...: ")
)
(while (= ss1 nil)
(setq ss1 (chonchu "\nChon text can cong them ...")
)
)
(setq i 0
num2 (getreal Ostr)
sslen (sslength ss1)
)
(if (/= num2 nil)
(setq
numadd num2
)
)
(if (/= numadd nil)
(setq Ostr (strcat "\nNhap gia tri tang them <"
(rtos numadd 2 2)
"> : "
)
)
)
(while (<= i (1- sslen))
(setq num1 (atof (bocchu ss1 i))
)
(setq num (+ num1 numadd))
(setq ob (bocdt ss1 i))
;(if (< num 10)
; (setq st (strcat "0" (connumint num)))
(setq st (sothanhchu num))
; )
(thaychu ob st)
(princ)
(setq i (1+ i))
)
)
;;; Sua nhieu text (cong tru gia tri nguyen)
(defun c:4 ()
(intro)
(command "undo" "mark")
(setq ss1 (chonchu "\nChon text can cong them ...")
)
(if (= Ostr nil)
(setq Ostr "\nNhap gia tri tang them <>...: ")
)
(while (= ss1 nil)
(setq ss1 (chonchu "\nChon text can cong them ...")
)
)
(setq i 0
num2 (getint Ostr)
sslen (sslength ss1)
)
(if (/= num2 nil)
(setq
numadd num2
)
)
(if (/= numadd nil)
(setq Ostr (strcat "\nNhap gia tri tang them <"
(rtos numadd 2 0)
"> : "
)
)
)
(while (<= i (1- sslen))
(setq num1 (atof (bocchu ss1 i))
)
(setq num (+ num1 numadd))
(setq ob (bocdt ss1 i))
(if (< num 10)
(setq st (strcat "0" (connumint num)))
(setq st (connumint num))
)
(thaychu ob st)
(princ)
(setq i (1+ i))
)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun c:5 ()
(intro)
(command "undo" "mark")
(setq ss1 (chonchu "\nChon text can cong them ...")
)
(if (= Ostr nil)
(setq Ostr "\nNhap gia tri tang them <>...: ")
)
(while (= ss1 nil)
(setq ss1 (chonchu "\nChon text can cong them ...")
)
)
(setq i 0
num2 (getreal Ostr)
sslen (sslength ss1)
)
(if (/= num2 nil)
(setq
numadd num2
)
)
(if (/= numadd nil)
(setq Ostr (strcat "\nNhap gia tri tang them <"
(rtos numadd 2 2)
"> : "
)
)
)
(while (<= i (1- sslen))
(setq num1 (atof (bocchu ss1 i))
)
(setq num (+ num1 numadd))
(setq ob (bocdt ss1 i))
(if (> num 0)
(setq st (strcat "+" (sothanhchu num)))
(setq st (sothanhchu num))
)
(thaychu ob st)
(princ)
(setq i (1+ i))
)
)Thảo luận gốc
Lisp được chia sẻ trong chủ đề Cần gấp lisp tăng giá trị khi chọn. Xem đúng bài viết #22277 để đọc hướng dẫn và trao đổi thêm.