viết lisp tính chiều dài trung bình của nhiều đoạn thẳng
Bạn dùng tạm cái này, lệnh tb :
(defun add_mline () (foreach e_record_sub e_record (cond ((= 10 (car e_record_sub)) (setq pt1 (cdr e_record_sub) mline_len 0.0 ) ) ((= 11 (car e_record_sub)) (setq pt2 (cdr e_record_sub) mline_len (+ mline_len (distance pt2 pt1)) pt1 pt2 ) ) ) ) (setq tot_len (+ tot_len mline_len)) (ssdel e_name ss) ) (defun C:tb (/ tot_len ss e_name e_record e_type) (grtext -1 "Free from cadviet.com @ketxu") (setq k (getvar "dimlfac")) (setq tot_len 0.0) (setq ss (ssget)) (setq len (sslength ss)) (if (null ss) (exit) ) (while (> (sslength ss) 0) (setq e_name (ssname ss 0)) (setq e_record (entget e_name)) (setq e_type (cdr (assoc '0 e_record))) (cond ((wcmatch e_type "LINE,ARC,CIRCLE,POLYLINE,LWPOLYLINE,ELLIPSE,SPLINE") (command "lengthen" e_name "") (setq tot_len (+ tot_len (getvar "PERIMETER"))) (ssdel e_name ss) ) ((wcmatch e_type "MLINE") (add_mline)) (e_type (ssdel e_name ss)) ) ) (setq tot_len (* k tot_len)) (setq tbinh (/ tot_len len)) (alert (rtos tbinh 2 2)) )
XIN ĐA TẠ CAO THỦ NHÉ! ĐÚNG Ý EM RỒI ĐẤY!
- Tải lisp
- 139510_tb.lsp
Cách dùng
- Tải tệp 139510_tb.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 TB để chạy lisp.
Mã nguồn 139510_tb.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/
(defun add_mline ()
(foreach e_record_sub e_record
(cond ((= 10 (car e_record_sub))
(setq pt1 (cdr e_record_sub)
mline_len 0.0
)
)
((= 11 (car e_record_sub))
(setq pt2 (cdr e_record_sub)
mline_len (+ mline_len (distance pt2 pt1))
pt1 pt2
)
)
)
)
(setq tot_len (+ tot_len mline_len))
(ssdel e_name ss)
)
(defun C:tb (/ tot_len ss e_name e_record e_type)
(grtext -1 "Free from cadviet.com @ketxu")
(setq k (getvar "dimlfac"))
(setq tot_len 0.0)
(setq ss (ssget))
(setq len (sslength ss))
(if (null ss)
(exit)
)
(while (> (sslength ss) 0)
(setq e_name (ssname ss 0))
(setq e_record (entget e_name))
(setq e_type (cdr (assoc '0 e_record)))
(cond ((wcmatch e_type "LINE,ARC,CIRCLE,POLYLINE,LWPOLYLINE,ELLIPSE,SPLINE")
(command "lengthen" e_name "")
(setq tot_len (+ tot_len (getvar "PERIMETER")))
(ssdel e_name ss)
)
((wcmatch e_type "MLINE") (add_mline))
(e_type (ssdel e_name ss))
)
)
(setq tot_len (* k tot_len))
(setq tbinh (/ tot_len len))
(alert (rtos tbinh 2 2))
)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 #139510 để đọc hướng dẫn và trao đổi thêm.