Jump to content

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)
)

Cách dùng

  1. Tải tệp 295441_sd.lsp về máy.
  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 SD để chạy lisp.

Mã nguồn 295441_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
	  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)
)

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 #295441 để đọc hướng dẫn và trao đổi thêm.

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