Lisp lệnh TKT trong chủ đề “lisp tính tổng chiều dài các line hay pline”
Rảnh nên làm bậy, bác Bình đừng quở nhé ! :D
;; free lisp from cadviet.com ;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/3778-lisp-tinh-tong-chieu-dai-cac-line-hay-pline/ ;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Sua theo yeu cau cua Khang (Cadviet) de thong ke thep co cong them doan noi = 30\40*d khi Lthanh >1170mm, luu y ham add_mline ko sua vi thep thuong ko ve bang mline (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) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;Doi ten lenh thanh TKT = thong ke thep de khoi lan lon ! (defun C:TKT (/ tot_len ss e_name e_record e_type dk hs len_i) (princ "\nCADViet.com © 2007") (setq cmd (getvar "cmdecho")) (setvar "cmdecho" 0) (setq tot_len 0.0) (setq ss (ssget)) (initget 1) (setq dk (getreal "\nNhap duong kinh thanh thep (mm): ")) (initget 1 "30d 40d") (setq hs (atof (getkword "\nNhap chieu dai doan noi <30d/40d>: "))) (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 len_i (getvar "PERIMETER")) (setq len_i (+ (* hs dk (fix (/ len_i 1170))) len_i)) (setq tot_len (+ tot_len len_i)) (ssdel e_name ss) ) ((wcmatch e_type "MLINE") (add_mline)) (e_type (ssdel e_name ss)) ) ) (prompt (strcat "\nTong chieu dai thep (da tinh phan moi noi): " (rtos tot_len 2 2))) (princ) ) (setvar "cmdecho" cmd) (princ)
- Tải lisp
- 270155_tkt.lsp
Cách dùng
- Tải tệp 270155_tkt.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 TKT để chạy lisp.
Mã nguồn 270155_tkt.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/3778-lisp-t%C3%ADnh-t%E1%BB%95ng-chi%E1%BB%81u-d%C3%A0i-c%C3%A1c-line-hay-pline/
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/3778-lisp-tinh-tong-chieu-dai-cac-line-hay-pline/
;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Sua theo yeu cau cua Khang (Cadviet) de thong ke thep co cong them doan noi = 30\40*d khi Lthanh >1170mm, luu y ham add_mline ko sua vi thep thuong ko ve bang mline
(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)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;Doi ten lenh thanh TKT = thong ke thep de khoi lan lon !
(defun C:TKT (/ tot_len ss e_name e_record e_type dk hs len_i)
(princ "\nCADViet.com © 2007")
(setq cmd (getvar "cmdecho"))
(setvar "cmdecho" 0)
(setq tot_len 0.0)
(setq ss (ssget))
(initget 1)
(setq dk (getreal "\nNhap duong kinh thanh thep (mm): "))
(initget 1 "30d 40d")
(setq hs (atof (getkword "\nNhap chieu dai doan noi <30d/40d>: ")))
(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 len_i (getvar "PERIMETER"))
(setq len_i (+ (* hs dk (fix (/ len_i 1170))) len_i))
(setq tot_len (+ tot_len len_i))
(ssdel e_name ss)
)
((wcmatch e_type "MLINE") (add_mline))
(e_type (ssdel e_name ss))
)
)
(prompt (strcat "\nTong chieu dai thep (da tinh phan moi noi): " (rtos tot_len 2 2)))
(princ)
)
(setvar "cmdecho" cmd)
(princ)Thảo luận gốc
Lisp được chia sẻ trong chủ đề lisp tính tổng chiều dài các line hay pline. Xem đúng bài viết #270155 để đọc hướng dẫn và trao đổi thêm.