Jump to content

Lisp lệnh HA trong chủ đề “Lisp Tự Động Đo Và Ghi Kích Thước Nhiều Đối Tượng”

Mình  sửa luôn trong lisp bác #Ha < bên dưới này > cho bạn. Bạn copy về xem thế nào. Bạn nên cám ơn những người cống hiến vì diễn đàn nhiều như bác Kết vs bác Bee kia kìa. :) Mình đi học mót thôi, trình còn gà lắm.

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/55599-yeu-cau-lisp-lay-gia-tri-cua-dimenson-text-va-xuat-ra-file-text/


(defun C:HA( / lst fn fw index x y z txt)	;Doan Van Ha Cadviet.com

 (princ "\nChon cac Text/Mtext/Dimension can xuat ra file...")

 (setq lst (acet-ss-to-list (ssget '((0 . "*TEXT,DIMENSION"))))

       	fn (getfiled "Chon file de save" "" "csv" 1)

       	fw (open fn "w")

       	index 0 x 1 y 1 z 1)

 (repeat (length lst)

  (cond

   ((= (cdr (assoc 0 (entget (nth index lst)))) "TEXT") (setq txt (strcat (cdr (assoc 1 (entget (nth index lst)))) "," "text" (itoa x)) x (1+ x)))

   ((= (cdr (assoc 0 (entget (nth index lst)))) "MTEXT") (setq txt (strcat (cdr (assoc 1 (entget (nth index lst)))) "," "mtext" (itoa y)) y (1+ y)))

   ((= (cdr (assoc 0 (entget (nth index lst)))) "DIMENSION")

	(if (= (cdr (assoc 1 (entget (nth index lst)))) "")

 	(setq txt (strcat (rtos (cdr (assoc 42 (entget (nth index lst))))) "," "dim" (itoa z) "," (cdr (assoc 8 (entget (nth index lst))))) z (1+ z))

 	(setq txt (strcat (cdr (assoc 1 (entget (nth index lst)))) "," "dim" (itoa z)  "," (cdr (assoc 8 (entget (nth index lst))))) z (1+ z)))))

  (princ (strcat txt "\n") fw)

  (setq index (1+ index)))

 (close fw))



Cách dùng

  1. Tải tệp 413448_ha.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 HA để chạy lisp.

Mã nguồn 413448_ha.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/168069-lisp-t%E1%BB%B1-%C4%91%E1%BB%99ng-%C4%91o-v%C3%A0-ghi-k%C3%ADch-th%C6%B0%E1%BB%9Bc-nhi%E1%BB%81u-%C4%91%E1%BB%91i-t%C6%B0%E1%BB%A3ng/
;; free lisp from cadviet.com;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/55599-yeu-cau-lisp-lay-gia-tri-cua-dimenson-text-va-xuat-ra-file-text/  (defun C:HA( / lst fn fw index x y z txt)	;Doan Van Ha Cadviet.com  (princ "\nChon cac Text/Mtext/Dimension can xuat ra file...")  (setq lst (acet-ss-to-list (ssget '((0 . "*TEXT,DIMENSION"))))        	fn (getfiled "Chon file de save" "" "csv" 1)        	fw (open fn "w")        	index 0 x 1 y 1 z 1)  (repeat (length lst)   (cond    ((= (cdr (assoc 0 (entget (nth index lst)))) "TEXT") (setq txt (strcat (cdr (assoc 1 (entget (nth index lst)))) "," "text" (itoa x)) x (1+ x)))    ((= (cdr (assoc 0 (entget (nth index lst)))) "MTEXT") (setq txt (strcat (cdr (assoc 1 (entget (nth index lst)))) "," "mtext" (itoa y)) y (1+ y)))    ((= (cdr (assoc 0 (entget (nth index lst)))) "DIMENSION") 	(if (= (cdr (assoc 1 (entget (nth index lst)))) "")  	(setq txt (strcat (rtos (cdr (assoc 42 (entget (nth index lst))))) "," "dim" (itoa z) "," (cdr (assoc 8 (entget (nth index lst))))) z (1+ z))  	(setq txt (strcat (cdr (assoc 1 (entget (nth index lst)))) "," "dim" (itoa z)  "," (cdr (assoc 8 (entget (nth index lst))))) z (1+ z)))))   (princ (strcat txt "\n") fw)   (setq index (1+ index)))  (close fw))   

Thảo luận gốc

Lisp được chia sẻ trong chủ đề Lisp Tự Động Đo Và Ghi Kích Thước Nhiều Đối Tượng. Xem đúng bài viết #413448 để đọc hướng dẫn và trao đổi thêm.

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