Lisp lệnh DIMSUM trong chủ đề “Tính Tổng Chiều Dài Dim”
chào các pro , hiện e có 1 vấn đề nhỏ, đó là có thể có cách nào tính tổng các giá trị chiều dài trong Dim ko? thanks all
Search thôi.
(defun c:DimSum (/ #SSList)
(and (setq #SSList (AT:SS->List (ssget '((0 . "DIMENSION"))) T))
(alert
(strcat "Total Distance: "
(vl-princ-to-string
(apply '+ (mapcar 'vla-get-measurement #SSList))
) ;_ vl-princ-to-string
"'"
) ;_ strcat
) ;_ alert
) ;_ and
(princ)
) ;_ defun
;;; Convert selection set to list of ename or vla objects
;;; #Selection - SSGET selection set
;;; #VLAList - T for vla objects, nil for ename
;;; Alan J. Thompson, 04.20.09
(defun AT:SS->List (#Selection #VlaList / #List)
(and #Selection
(setq #List (vl-remove-if
'listp
(mapcar 'cadr (ssnamex #Selection))
) ;_ vl-remove-if
) ;_ setq
#VlaList
(setq #List (mapcar 'vlax-ename->vla-object #List))
) ;_ and
#List
) ;_ defun
- Tải lisp
- 408455_dimsum.lsp
Cách dùng
- Tải tệp 408455_dimsum.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 DIMSUM để chạy lisp.
Mã nguồn 408455_dimsum.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/166128-t%C3%ADnh-t%E1%BB%95ng-chi%E1%BB%81u-d%C3%A0i-dim/
(defun c:DimSum (/ #SSList)
(and (setq #SSList (AT:SS->List (ssget '((0 . "DIMENSION"))) T))
(alert
(strcat "Total Distance: "
(vl-princ-to-string
(apply '+ (mapcar 'vla-get-measurement #SSList))
) ;_ vl-princ-to-string
"'"
) ;_ strcat
) ;_ alert
) ;_ and
(princ)
) ;_ defun
;;; Convert selection set to list of ename or vla objects
;;; #Selection - SSGET selection set
;;; #VLAList - T for vla objects, nil for ename
;;; Alan J. Thompson, 04.20.09
(defun AT:SS->List (#Selection #VlaList / #List)
(and #Selection
(setq #List (vl-remove-if
'listp
(mapcar 'cadr (ssnamex #Selection))
) ;_ vl-remove-if
) ;_ setq
#VlaList
(setq #List (mapcar 'vlax-ename->vla-object #List))
) ;_ and
#List
) ;_ defunThảo luận gốc
Lisp được chia sẻ trong chủ đề Tính Tổng Chiều Dài Dim. Xem đúng bài viết #408455 để đọc hướng dẫn và trao đổi thêm.