Lisp lệnh TCDT trong chủ đề “Nhờ gộp 2 lisp”
(vl-load-com)
;;;--------------------------------------------------------------------
(defun _Length(e) (vlax-curve-getDistAtParam e (vlax-curve-getEndParam e)))
(defun _Area(e) (vlax-curve-getarea e))
(defun wtxt (txt p / sty d h)
(setq
sty (getvar "textstyle")
d (tblsearch "style" sty)
h (getvar "textsize")
)
(entmake (list (cons 0 "TEXT") (cons 7 sty) (cons 1 txt) (cons 10 p)
(if (> h 0) (cons 40 h) (assoc 40 d)) (assoc 41 d))
)
)
;;;--------------------------------------------------------------------
(defun C:tcdt( / ss L S e)
(and (setq ss (ssget (list (cons 0 "LINE,ARC,CIRCLE,POLYLINE,LWPOLYLINE,ELLIPSE,SPLINE")))
L 0.0 S 0.0)
(while (setq e (ssname ss 0))
(setq L (+ L (_Length e)) S (+ S (_Area e)))
(ssdel e ss)
)
(alert (strcat "Total length = " (rtos L) " units.\nTotal Area = " (rtos S) "units."))
)
(wtxt (rtos L 2 0) (getpoint "\nPoint to write Total length : "))
(wtxt (rtos S 2 0) (getpoint "\nPoint to write Total Area : "))
)
Xem được chưa bạn
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 425483_tcdt.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 TCDT để chạy lisp.
Mã nguồn 425483_tcdt.lsp (trích từ bài viết gốc)
(vl-load-com)
;;;--------------------------------------------------------------------
(defun _Length(e) (vlax-curve-getDistAtParam e (vlax-curve-getEndParam e)))
(defun _Area(e) (vlax-curve-getarea e))
(defun wtxt (txt p / sty d h)
(setq
sty (getvar "textstyle")
d (tblsearch "style" sty)
h (getvar "textsize")
)
(entmake (list (cons 0 "TEXT") (cons 7 sty) (cons 1 txt) (cons 10 p)
(if (> h 0) (cons 40 h) (assoc 40 d)) (assoc 41 d))
)
)
;;;--------------------------------------------------------------------
(defun C:tcdt( / ss L S e)
(and (setq ss (ssget (list (cons 0 "LINE,ARC,CIRCLE,POLYLINE,LWPOLYLINE,ELLIPSE,SPLINE")))
L 0.0 S 0.0)
(while (setq e (ssname ss 0))
(setq L (+ L (_Length e)) S (+ S (_Area e)))
(ssdel e ss)
)
(alert (strcat "Total length = " (rtos L) " units.\nTotal Area = " (rtos S) "units."))
)
(wtxt (rtos L 2 0) (getpoint "\nPoint to write Total length : "))
(wtxt (rtos S 2 0) (getpoint "\nPoint to write Total Area : "))
)Thảo luận gốc
Lisp được chia sẻ trong chủ đề Nhờ gộp 2 lisp. Xem đúng bài viết #425483 để đọc hướng dẫn và trao đổi thêm.