viết lisp tính chiều dài trung bình của nhiều đoạn thẳng
Cái chọn K máy bạn không được, mình không rõ lắm vì máy mình ok (Bạn thử kiểm tra lại chế độ bắt điểm)
bạn thử xem
(prompt "command : dai") (defun c:dai() (setq tong 0) (setq th (ssget)) (setq index 0) (setq dtuong (sslength th)) (while (< index dtuong) (setq ds (entget (ssname th index))) (command "lengthen" (ssname th index) "" ) (setq tong (+ tong (getvar "perimeter"))) (setq index (1+ index)) ) (print tong) (prompt "Ghi text moi <G> hay thay the text (T) :") (setq luachon (getstring)) (setq luachon (strcase luachon)) (if (= "" luachon) (setq luachon "G")) (if (= "G" luachon) (progn (setq pt1 (getpoint)) (setq h (/ (getvar "viewsize") 20)) (command "text" pt1 h "" tong) ) ) (if (= "T" luachon) (progn (prompt "\n Chon gia tri can thay the") (SETQ TT (SSGET)) (setq s (entget (SSNAME TT 0))) (setq otext (assoc 1 s)) (setq ot (cdr otext)) (setq ot (read (substr ot 1 ))) (setq nt (cons 1 (rtos tong 2))) ;(setq s (subst nt otext s)) (setq s (subst (cons 62 80) (assoc 62 s) s)) (setq s (append s (list (cons 62 80)))) (entmod s) (princ) ) ) )Tôi chỉ sửa qua được vậy thôi :D
Cái số 80 là mầu, bạn thích mầu nào thay số 80=màu (1...256)
Hề hề hề,
Bác NguyenNgocSon xem lại dòng code này:
(command "text" pt1 h "" tong)
Hình như chỗ "" phải là một giá trị số mới đúng bác ạ.
- Tải lisp
- 221096_dai.lsp
Cách dùng
- Tải tệp 221096_dai.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 DAI để chạy lisp.
Mã nguồn 221096_dai.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/38453-y%C3%AAu-c%E1%BA%A7u-vi%E1%BA%BFt-lisp-t%C3%ADnh-chi%E1%BB%81u-d%C3%A0i-trung-b%C3%ACnh-c%E1%BB%A7a-nhi%E1%BB%81u-%C4%91o%E1%BA%A1n-th%E1%BA%B3ng/
(prompt "command : dai")
(defun c:dai()
(setq tong 0)
(setq th (ssget))
(setq index 0)
(setq dtuong (sslength th))
(while (< index dtuong)
(setq ds (entget (ssname th index)))
(command "lengthen" (ssname th index) "" )
(setq tong (+ tong (getvar "perimeter")))
(setq index (1+ index))
)
(print tong)
(prompt "Ghi text moi <G> hay thay the text (T) :")
(setq luachon (getstring))
(setq luachon (strcase luachon))
(if (= "" luachon) (setq luachon "G"))
(if (= "G" luachon)
(progn
(setq pt1 (getpoint))
(setq h (/ (getvar "viewsize") 20))
(command "text" pt1 h "" tong)
)
)
(if (= "T" luachon)
(progn
(prompt "\n Chon gia tri can thay the")
(SETQ TT (SSGET))
(setq s (entget (SSNAME TT 0)))
(setq otext (assoc 1 s))
(setq ot (cdr otext))
(setq ot (read (substr ot 1 )))
(setq nt (cons 1 (rtos tong 2)))
;(setq s (subst nt otext s))
(setq s (subst (cons 62 80) (assoc 62 s) s))
(setq s (append s (list (cons 62 80))))
(entmod s)
(princ)
)
)
)
Thảo luận gốc
Lisp được chia sẻ trong chủ đề [Yêu cầu] viết lisp tính chiều dài trung bình của nhiều đoạn thẳng. Xem đúng bài viết #221096 để đọc hướng dẫn và trao đổi thêm.