Lisp lệnh TG trong chủ đề “lisp tính tổng chiều dài các line hay pline”
Mình thấy trên diễn đàn có lisp tính tổng chiều dài như thế này
(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:tg (/ tot_len ss e_name e_record e_type) (princ "\nCADViet.com © 2007") (setq tot_len 0.0) (setq ss (ssget)) (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)) ) ) (prompt (strcat "\nTotal length is: " (rtos tot_len 2 2))) (princ) ) (princ "\ntg - free lisp from www.cadviet.com") (princ)Bây giờ muốn mọi người sửa giúp kết quả cuối cùng là chọn text để ghi thay cho kết quả hiện ra trên màn hình, thanks.
Mình đang sử dụng lisp này ở cad 2012 trở xuống OK
Nhưng khong hiểu sao khi dùng trên Cad 2015 bản quyền thì lại bị lỗi,rõ ràng đã thông báo load thành công?
Bác nào có thể giải thích giúp em không,liệu có phải sửa gì không ah.
Nó báo:error funtion cancelled
Các bác giup em với.thanks
- Tải lisp
- 308099_tg.lsp
Cách dùng
- Tải tệp 308099_tg.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 TG để chạy lisp.
Mã nguồn 308099_tg.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/
(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:tg (/ tot_len ss e_name e_record e_type)
(princ "\nCADViet.com © 2007")
(setq tot_len 0.0)
(setq ss (ssget))
(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))
)
)
(prompt (strcat "\nTotal length is: " (rtos tot_len 2 2)))
(princ)
)
(princ "\ntg - free lisp from www.cadviet.com")
(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 #308099 để đọc hướng dẫn và trao đổi thêm.