Jump to content

Tính tổng diện tích các hình trên bản vẽ, "Ed" vào text sẵn có

Lệnh UDT (Update diện tích) dưới đây sẽ làm điều bạn muốn:

(defun c:udt(/ ss tong ham tmp tt)
 (setq
   ss (ssget '((-4 . "<OR")(0 . "LWPOLYLINE")(0 . "REGION")(0 . "CIRCLE")(0 . "ARC")(-4 . "OR>")))	
   tong 0.0
   ham (lambda (x) (command ".area" "o" x) (setq tong (+ tong (getvar "area"))))
   tmp (mapcar 'ham (ss2ent ss))  
   tt (entget (car (entsel "\nChon text ket qua: ")))
   tong (vl-string-right-trim "." (vl-string-right-trim "0" (rtos tong)))
 )
 (entmod (subst (cons 1 tong) (assoc 1 tt) tt))
)

(defun ss2ent(ss / sodt index lstent)
 (setq 
   sodt (if ss (sslength ss) 0)	 
   index 0
 )
 (repeat sodt
   (setq ent (ssname ss index)
  index (1+ index)
  lstent (cons ent lstent)
   )
 )
 (reverse lstent)
)
(princ "\nUpdate Area - free lisp from cadviet.com")
(princ "\nUse UDT command to start!")
(vl-load-com)

 

Cám ơn bác Hoanh nhé, yêu cầu của em đã được đáp ứng. Diễn đàn Cadviet rất có ích cho những cư dân dùng AutoCad. Năm mới, em chúc bác mạnh khỏe, thành đạt và hạnh phúc trong cuộc sống.

Cách dùng

  1. Tải tệp 10533_udt.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 UDT để chạy lisp.

Mã nguồn 10533_udt.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/2490-%C4%91%C3%A3-xong-t%C3%ADnh-t%E1%BB%95ng-di%E1%BB%87n-t%C3%ADch-c%C3%A1c-h%C3%ACnh-tr%C3%AAn-b%E1%BA%A3n-v%E1%BA%BD-ed-v%C3%A0o-text-s%E1%BA%B5n-c%C3%B3/
(defun c:udt(/ ss tong ham tmp tt)
 (setq
   ss (ssget '((-4 . "<OR")(0 . "LWPOLYLINE")(0 . "REGION")(0 . "CIRCLE")(0 . "ARC")(-4 . "OR>")))	
   tong 0.0
   ham (lambda (x) (command ".area" "o" x) (setq tong (+ tong (getvar "area"))))
   tmp (mapcar 'ham (ss2ent ss))  
   tt (entget (car (entsel "\nChon text ket qua: ")))
   tong (vl-string-right-trim "." (vl-string-right-trim "0" (rtos tong)))
 )
 (entmod (subst (cons 1 tong) (assoc 1 tt) tt))
)

(defun ss2ent(ss / sodt index lstent)
 (setq 
   sodt (if ss (sslength ss) 0)	 
   index 0
 )
 (repeat sodt
   (setq ent (ssname ss index)
  index (1+ index)
  lstent (cons ent lstent)
   )
 )
 (reverse lstent)
)
(princ "\nUpdate Area - free lisp from cadviet.com")
(princ "\nUse UDT command to start!")
(vl-load-com)

Thảo luận gốc

Lisp được chia sẻ trong chủ đề [Đã xong] Tính tổng diện tích các hình trên bản vẽ, "Ed" vào text sẵn có. Xem đúng bài viết #10533 để đọc hướng dẫn và trao đổi thêm.

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