Lisp lệnh SD trong chủ đề “[yêu cầu] lisp tính tổng số đai trong dim”
Bạn dùng tạm cái này
Chú ý: đang còn hạn chế, Khi chọn nhầm các loại Dim style không phù hợp thì lisp lỗi ko chạy :D :D :D
;; Lisp cong gia tri Dim, phuc vu tinh tong so cot dai theo y/c: ;;https://www.cadviet.com/forum/topic/102605-yeu-cau-lisp-tinh-tong-so-dai-trong-dim/ (defun c:SD (/ i tong ss ent info ds ds_name hs text_dim start end n) ;;sum dim (setq i -1 tong 0) (prompt "\n Chon Dim can tinh tong: ") (setq ss (ssget '((0 . "DIMENSION")))) (while (and ss (< i (1- (sslength ss)))) (setq ent (ssname ss (setq i (1+ i))) info (entget ent) ds (cdr (assoc 3 info)) ds_name (tblobjname "dimstyle" ds) hs (cdr (assoc 143 (entget ds_name))) ) (cond ((= (cdr(assoc 1 info)) "") (setq n (fix (+ 0.5 (* (cdr(assoc 42 info)) hs))))) (t (setq text_dim (cdr(assoc 1 info)) start (vl-string-search "[" text_dim) end (vl-string-search "%%C" text_dim) n (atoi (substr text_dim (+ 2 start) (- end start 1))) ) ) ) (setq tong (+ n tong)) ) (alert (strcat "Tong cong " (itoa (1+ i)) " dim la: " (itoa tong) " dai")) (princ) )Đúng là khi chọn nhầm dim khác bị lỗi, ko chạy được nhưng cám ơn bạn đã nhiệt tình giúp mình nhé
Mình "cố tình" làm thế vì BV mẫu bạn đưa ra & những thông tin bạn cấp ko đủ để mình lọc Dim style
Nếu muốn chạy trơn tru nữa thì bạn cần cung cấp thông tin đầy đủ từ đầu :D
Nếu chấp nhận bỏ qua dim style ko phù hợp (ko có hs chuyển đổi đơn vị) thì dùng cái này
;; Lisp cong gia tri Dim, phuc vu tinh tong so cot dai theo y/c: ;;https://www.cadviet.com/forum/topic/102605-yeu-cau-lisp-tinh-tong-so-dai-trong-dim/ (defun c:SD (/ i tong ss ent info ds ds_name hs text_dim start end n) ;;sum dim (setq i -1 j 0 tong 0) (prompt "\n Chon Dim can tinh tong: ") (setq ss (ssget '((0 . "DIMENSION")))) (while (and ss (< i (1- (sslength ss)))) (setq ent (ssname ss (setq i (1+ i))) info (entget ent) ds (cdr (assoc 3 info)) ds_name (tblobjname "dimstyle" ds) hs (cdr (assoc 143 (entget ds_name))) ) (cond ((null hs) (setq n 0 j (1+ j))) ((= (cdr(assoc 1 info)) "") (setq n (fix (+ 0.5 (* (cdr(assoc 42 info)) hs))))) (t (setq text_dim (cdr(assoc 1 info)) start (vl-string-search "[" text_dim) end (vl-string-search "%%C" text_dim) n (atoi (substr text_dim (+ 2 start) (- end start 1))) ) ) ) (setq tong (+ n tong)) ) (alert (strcat "Tong cong " (itoa (1+ (- i j))) " dim la: " (itoa tong) " dai")) (princ) )
- Tải lisp
- 295449_sd.lsp
Cách dùng
- Tải tệp 295449_sd.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 SD để chạy lisp.
Mã nguồn 295449_sd.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/102605-y%C3%AAu-c%E1%BA%A7u-lisp-t%C3%ADnh-t%E1%BB%95ng-s%E1%BB%91-%C4%91ai-trong-dim/
;; Lisp cong gia tri Dim, phuc vu tinh tong so cot dai theo y/c:
;;https://www.cadviet.com/forum/topic/102605-yeu-cau-lisp-tinh-tong-so-dai-trong-dim/
(defun c:SD (/ i tong ss ent info ds ds_name hs text_dim start end n)
;;sum dim
(setq i -1
j 0
tong 0)
(prompt "\n Chon Dim can tinh tong: ")
(setq ss (ssget '((0 . "DIMENSION"))))
(while (and ss (< i (1- (sslength ss))))
(setq ent (ssname ss (setq i (1+ i)))
info (entget ent)
ds (cdr (assoc 3 info))
ds_name (tblobjname "dimstyle" ds)
hs (cdr (assoc 143 (entget ds_name)))
)
(cond ((null hs) (setq n 0 j (1+ j)))
((= (cdr(assoc 1 info)) "") (setq n (fix (+ 0.5 (* (cdr(assoc 42 info)) hs)))))
(t (setq text_dim (cdr(assoc 1 info))
start (vl-string-search "[" text_dim)
end (vl-string-search "%%C" text_dim)
n (atoi (substr text_dim (+ 2 start) (- end start 1)))
)
)
)
(setq tong (+ n tong))
)
(alert (strcat "Tong cong " (itoa (1+ (- i j))) " dim la: " (itoa tong) " dai"))
(princ)
)Thảo luận gốc
Lisp được chia sẻ trong chủ đề [yêu cầu] lisp tính tổng số đai trong dim. Xem đúng bài viết #295449 để đọc hướng dẫn và trao đổi thêm.