Jump to content

Lisp lệnh LEN trong chủ đề “đo SPL nhanh nhất _ HTR”


Bổ sung tùy chọn xuất Text : ghi Text cho từng đoạn - Chỉ ghi Text tổng - Không ghi Text .

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

  1. Chép mã nguồn, lưu thành tệp 73840_len.lsp.
  2. 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ẽ.
  3. Gõ lệnh LEN để chạy lisp.

Mã nguồn 73840_len.lsp (trích từ bài viết gốc)

(defun c:len (/ *error* vl ov ob p1 p2 pa1 pa2 len txt_opt total_len)
 (defun *error* (msg)
   (if ov (mapcar 'setvar vl ov))
   (if ob (redraw ob 4))
   (if (not(wcmatch (strcase msg) "*BREAK,*EXIT*,*CANCEL*"))
     (princ (strcat "\n** Error: " msg " **")))
   (princ))

 (defun put_txt (txt / pt)
   (if (setq pt (getpoint "\nDiem dat Text..."))
     (entmake (list '(0 . "TEXT")
                (cons 10 pt)
                (cons 40 (* (getvar "dimtxt")(getvar "dimscale")))
                (cons 1 txt)
                (cons 7 (getvar "TEXTSTYLE"))
                '(71 . 0)
                (cons 72 0)
                '(73 . 1)
                (cons 11 pt))))
   )

 (vl-load-com)
 (setq vl '("CMDECHO" "OSMODE" "orthomode")
       ov (mapcar 'getvar vl))
 (mapcar 'setvar vl '(0 33 0))    
 (while
   (not
     (and
(setq ob (car(entsel "\nChon doi tuong can do (LINE,ARC,SPLINE,LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE) : ")))
(if ob (wcmatch (cdr (assoc 0 (entget ob))) "*LINE,ARC,CIRCLE,ELLIPSE") )
)
     )
   (alert "\nDoi tuong da chon khong phu hop.
           \nChap nhan cac doi tuong : LINE,ARC,SPLINE,LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE
    \nChon lai :")
   )
 (redraw ob 3)
 (or *txt_opt* (setq *txt_opt* "None"))
 (initget "Each Total None" )
 (setq txt_opt (getkword (strcat "\nCach ghi Text : [Each/Total/None]. <" *txt_opt* ">"))
total_len 0)
 (if (= txt_opt "")(setq txt_opt *txt_opt*)(setq *txt_opt* txt_opt))
 (while (and
   (setq p1 (getpoint "\nTu diem :"))
   (setq p2 (getpoint "\nDem diem :"))
   )
   (if (and
  (setq pa1 (vlax-curve-getParamAtPoint ob p1))
  (setq pa2 (vlax-curve-getParamAtPoint ob p2))
  )
     (progn
(setq len (abs (- (vlax-curve-getdistatparam ob pa1)
		  (vlax-curve-getdistatparam ob pa2))) )
(setq total_len (+ len total_len))
(princ (strcat "\nChieu dai = " (rtos len) "  Tong chieu dai = " (rtos total_len)))
(if (= txt_opt "Each")
  (put_txt (rtos len)) )
)
     (alert "\nDiem chon khong thuoc doi tuong can do ! \nChon lai :" )
     )
   )
 (if (member txt_opt '("Each" "Total"))
   (put_txt (strcat "Tong = " (rtos total_len))) )
 (redraw ob 4)
 (mapcar 'setvar vl ov)
 (princ)
)

Thảo luận gốc

Lisp được chia sẻ trong chủ đề đo SPL nhanh nhất _ HTR. Xem đúng bài viết #73840 để đọc hướng dẫn và trao đổi thêm.

Về Thư viện AutoLisp (trang 5)