Lisp lệnh TG trong chủ đề “[Nhờ chỉnh sửa]Lisp tính tổng độ dài đoạn thẳng.”
Hi vọng đúng cái bạn cần.
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/index.php?showtopic=763
(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 txtpnt txtht)
(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))
)
)
(setq txtpnt (getpoint "\nSpecify start point of text."))
(setq txtht
(getdist (strcat "\nSpecify height <"
(rtos (getvar "textsize") 2 2)
">: "
)
)
)
(if (null txtht)
(setq txtht (getvar "textsize"))
)
(command "text"
"m"
txtpnt
txtht
0
(strcat (rtos (/ tot_len 1000) 2 2) "m")
)
(princ)
)
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 202650_tg.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 TG để chạy lisp.
Mã nguồn 202650_tg.lsp (trích từ bài viết gốc)
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/index.php?showtopic=763
(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 txtpnt txtht)
(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))
)
)
(setq txtpnt (getpoint "\nSpecify start point of text."))
(setq txtht
(getdist (strcat "\nSpecify height <"
(rtos (getvar "textsize") 2 2)
">: "
)
)
)
(if (null txtht)
(setq txtht (getvar "textsize"))
)
(command "text"
"m"
txtpnt
txtht
0
(strcat (rtos (/ tot_len 1000) 2 2) "m")
)
(princ)
)Thảo luận gốc
Lisp được chia sẻ trong chủ đề [Nhờ chỉnh sửa]Lisp tính tổng độ dài đoạn thẳng.. Xem đúng bài viết #202650 để đọc hướng dẫn và trao đổi thêm.