Lisp thống kê kích thước trong bản vẽ cad
Visual Lisp :
(defun c:tkd(/ lstval stp lst pw)
(setq stp 2) ;Dong nay quy dinh so le muon in ra
(cond ((ssget (list (cons 0 "DIMENSION")))
(defun dimval (e / a)(if (= (setq a(vla-get-TextOverride e)) "")
(rtos (vla-get-Measurement e) 2 stp)
(rtos (distof a) 2 stp)))
(vlax-for dObj (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object)))
(if (not (assoc (setq b (dimval dObj)) lst))
(setq lst (cons (cons b 1) lst))
(setq lst (subst (cons b (1+ (cdr (assoc b lst))))(assoc b lst) lst))
)
)
(setq pw (open (getfiled "Chon file de xuat ket qua" "" "xls" 1) "w"))
(write-line (strcat "Chieu dai" "\t" "So luong") pw)
(mapcar '(lambda(x)(write-line (strcat (car x) (chr 9) (itoa (cdr x))) pw)) lst)
(close pw)
)
)
)
(defun c:tkd(/ lstval stp lst pw)
(setq stp 2) ;Dong nay quy dinh so le muon in ra
(cond ((ssget (list (cons 0 "DIMENSION")))
(defun dimval (e / a)(if (= (setq a(vla-get-TextOverride e)) "")
(rtos (vla-get-Measurement e) 2 stp)
(rtos (distof a) 2 stp)))
(vlax-for dObj (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object)))
(if (not (assoc (setq b (dimval dObj)) lst))
(setq lst (cons (cons b 1) lst))
(setq lst (subst (cons b (1+ (cdr (assoc b lst))))(assoc b lst) lst))
)
)
(setq pw (open (getfiled "Chon file de xuat ket qua" "" "xls" 1) "w"))
(write-line (strcat "Chieu dai" "\t" "So luong") pw)
(mapcar '(lambda(x)(write-line (strcat (car x) (chr 9) (itoa (cdr x))) pw)) lst)
(close pw)
)
)
)
- Tải lisp
- 200487_tkd.lsp
Cách dùng
- Tải tệp 200487_tkd.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 TKD để chạy lisp.
Mã nguồn 200487_tkd.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/64087-y%C3%AAu-c%E1%BA%A7u-lisp-th%E1%BB%91ng-k%C3%AA-k%C3%ADch-th%C6%B0%E1%BB%9Bc-trong-b%E1%BA%A3n-v%E1%BA%BD-cad/
(defun c:tkd(/ lstval stp lst pw)
(setq stp 2) ;Dong nay quy dinh so le muon in ra
(cond ((ssget (list (cons 0 "DIMENSION")))
(defun dimval (e / a)(if (= (setq a(vla-get-TextOverride e)) "")
(rtos (vla-get-Measurement e) 2 stp)
(rtos (distof a) 2 stp)))
(vlax-for dObj (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object)))
(if (not (assoc (setq b (dimval dObj)) lst))
(setq lst (cons (cons b 1) lst))
(setq lst (subst (cons b (1+ (cdr (assoc b lst))))(assoc b lst) lst))
)
)
(setq pw (open (getfiled "Chon file de xuat ket qua" "" "xls" 1) "w"))
(write-line (strcat "Chieu dai" "\t" "So luong") pw)
(mapcar '(lambda(x)(write-line (strcat (car x) (chr 9) (itoa (cdr x))) pw)) lst)
(close pw)
)
)
)
Thảo luận gốc
Lisp được chia sẻ trong chủ đề [Yêu cầu] Lisp thống kê kích thước trong bản vẽ cad. Xem đúng bài viết #200487 để đọc hướng dẫn và trao đổi thêm.