Lisp tính tổng độ dài đoạn thẳng.
Viết nhanh cho bạn đây.
;Doan Van Ha - CADViet.com - Ngay 22/4/2012 ;Muc dich: Tinh tong chieu dai cac doi tuong, ghi len text, ghi ra file. (defun C:HA () (vl-load-com) (setq lst '()) (while (setq ss (ssget '((0 . "*LINE,ARC,CIRCLE,ELLIPSE")))) (setq entlst (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))) (setq cdai 0) (foreach ent entlst (setq cdai (+ cdai (vlax-curve-getDistAtParam ent (vlax-curve-getEndParam ent))))) (setq a (assoc 1 (entget (setq ent (car (entsel "Chon Text de nhap chieu dai...")))))) (entmod (subst (cons 1 (rtos cdai 2 2)) a (entget ent))) (setq lst (cons cdai lst))) (if (not ss) (progn (initget "Y N") (setq ghi (getkword "\nGhi ra file <Y>: ")) (if (or (= ghi "Y") (= ghi nil)) (progn (setq fn (getfiled "Chon file de xuat ket qua" "" "txt" 1)) (setq pw (open fn "w")) (setq z 0 lst (reverse lst)) (repeat (length lst) (princ (strcat "Tong " (itoa (1+ z)) " = " (rtos (nth z lst) 2 2) "\n") pw) (setq z (1+ z))) (close pw))))) (princ))
Viết nhanh cho bạn đây.
;Doan Van Ha - CADViet.com - Ngay 22/4/2012 ;Muc dich: Tinh tong chieu dai cac doi tuong, ghi len text, ghi ra file. (defun C:HA () (vl-load-com) (setq lst '()) (while (setq ss (ssget '((0 . "*LINE,ARC,CIRCLE,ELLIPSE")))) (setq entlst (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))) (setq cdai 0) (foreach ent entlst (setq cdai (+ cdai (vlax-curve-getDistAtParam ent (vlax-curve-getEndParam ent))))) (setq a (assoc 1 (entget (setq ent (car (entsel "Chon Text de nhap chieu dai...")))))) (entmod (subst (cons 1 (rtos cdai 2 2)) a (entget ent))) (setq lst (cons cdai lst))) (if (not ss) (progn (initget "Y N") (setq ghi (getkword "\nGhi ra file <Y>: ")) (if (or (= ghi "Y") (= ghi nil)) (progn (setq fn (getfiled "Chon file de xuat ket qua" "" "txt" 1)) (setq pw (open fn "w")) (setq z 0 lst (reverse lst)) (repeat (length lst) (princ (strcat "Tong " (itoa (1+ z)) " = " (rtos (nth z lst) 2 2) "\n") pw) (setq z (1+ z))) (close pw))))) (princ))
Bác Ha ạ. Có vài điểm chưa đúng lắm bác ạ:
1. Lisp trên tính chiều dài theo tỉ lệ 1:1
2. Ý em thì các bước là: Tính tổng chiều dài lần 1, sửa vào text 1, tiếp theo tính chiều dài lần 2 luôn, sửa lần 2, rồi tính chiều dài lần 3 luôn, sửa lần 3 luôn... Khi muốn kết thúc thì gõ dấu cách( sau khi sửa text), rồi hỏi: Có lưu không.
Bác giúp em lần nữa với/
Thanks bác
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 215612_ha.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 HA để chạy lisp.
Mã nguồn 215612_ha.lsp (trích từ bài viết gốc)
;Doan Van Ha - CADViet.com - Ngay 22/4/2012
;Muc dich: Tinh tong chieu dai cac doi tuong, ghi len text, ghi ra file.
(defun C:HA ()
(vl-load-com)
(setq lst '())
(while (setq ss (ssget '((0 . "*LINE,ARC,CIRCLE,ELLIPSE"))))
(setq entlst (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
(setq cdai 0)
(foreach ent entlst
(setq cdai (+ cdai (vlax-curve-getDistAtParam ent (vlax-curve-getEndParam ent)))))
(setq a (assoc 1 (entget (setq ent (car (entsel "Chon Text de nhap chieu dai..."))))))
(entmod (subst (cons 1 (rtos cdai 2 2)) a (entget ent)))
(setq lst (cons cdai lst)))
(if (not ss)
(progn
(initget "Y N")
(setq ghi (getkword "\nGhi ra file <Y>: "))
(if (or (= ghi "Y") (= ghi nil))
(progn
(setq fn (getfiled "Chon file de xuat ket qua" "" "txt" 1))
(setq pw (open fn "w"))
(setq z 0 lst (reverse lst))
(repeat (length lst)
(princ (strcat "Tong " (itoa (1+ z)) " = " (rtos (nth z lst) 2 2) "\n") pw)
(setq z (1+ z)))
(close pw)))))
(princ))
;Doan Van Ha - CADViet.com - Ngay 22/4/2012
;Muc dich: Tinh tong chieu dai cac doi tuong, ghi len text, ghi ra file.
(defun C:HA ()
(vl-load-com)
(setq lst '())
(while (setq ss (ssget '((0 . "*LINE,ARC,CIRCLE,ELLIPSE"))))
(setq entlst (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
(setq cdai 0)
(foreach ent entlst
(setq cdai (+ cdai (vlax-curve-getDistAtParam ent (vlax-curve-getEndParam ent)))))
(setq a (assoc 1 (entget (setq ent (car (entsel "Chon Text de nhap chieu dai..."))))))
(entmod (subst (cons 1 (rtos cdai 2 2)) a (entget ent)))
(setq lst (cons cdai lst)))
(if (not ss)
(progn
(initget "Y N")
(setq ghi (getkword "\nGhi ra file <Y>: "))
(if (or (= ghi "Y") (= ghi nil))
(progn
(setq fn (getfiled "Chon file de xuat ket qua" "" "txt" 1))
(setq pw (open fn "w"))
(setq z 0 lst (reverse lst))
(repeat (length lst)
(princ (strcat "Tong " (itoa (1+ z)) " = " (rtos (nth z lst) 2 2) "\n") pw)
(setq z (1+ z)))
(close pw)))))
(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 #215612 để đọc hướng dẫn và trao đổi thêm.