Jump to content

lisp tính tổng diện tích

Em sưu tầm và có chỉnh sửa lại theo những yêu cầu của mình nhưng khổ nổi nó chỉ chạy được lần đầu tiên còn các lần sau nó đều báo lổi nhờ các bác ai biết sửa lại cho em:

(Defun c:TDT()
(setvar "cmdecho" 0)
(setvar "osmode" 0)
(command "osnap" "none")
(if (null am)(setq am "1"))
(Setq temp1 T)
(While temp1
(setq pt (strcat "\nHe so ("am") \<Chon diem>: "))
(Initget "h H")
(setq str (getpoint pt))
(Cond
((= str "h") (setq am (getstring (strcat"\nNhap he so <"am"> :"))))
((= str "H") (setq am (getstring (strcat"\nNhap he so <"am"> :"))))
(Progn
(Setq pt str)
(setq temp1 nil)
)
)
)
(setq s 0)
(progn
; (setq pt (getpoint "\n Chon diem: "))
(while pt
(setq entold (cdr (assoc 5 (entget (entlast)))))
(command "boundary" pt "")
(setq entnew (cdr (assoc 5 (entget (entlast)))))
(if (/= entold entnew)
(progn
(setq entnew (entget (entlast)))
(if (assoc 62 entnew)
(setq entnew (subst (cons 62 (+ 3 (cdr (assoc 62 entnew)))) (assoc 62 entnew) entnew))
(setq entnew (append entnew (list (cons 62 (+ 3 (cdr (assoc 62 (tblsearch "layer" (cdr (assoc 8 entnew))))))))))
)


(entmod entnew)
(Command "area" "o" (entlast))
(setq s (+ s (getvar "area")))
(setq pt (getpoint "\n Chon diem: "))
(entdel (entlast))
)
(progn
(princ "chon diem sai")
(setq pt (getpoint "\n Chon diem: "))
)
)
)
)

(command "osnap" "intersection")
(setq am (atof am))
(setq s (* s am))
(setq point (getpoint "\n Chon diem ghi dien tich: "))
(setq th (getvar "textsize"))
(setq th (getstring (strcat "\nChieu cao chu <"(rtos th)"> :")))
;(princ "\nDien tich nhung vung vua chon la: "s)
(command "TEXT" point th 0 (rtos s 2 2))
(setvar "MODEMACRO" "**CHUC BAN LAM VIEC HIEU QUA** TAILIEUKYTHUAT.COM")
(princ )
)

Tệp .lsp gốc không còn trên máy chủ. Hãy chép mã nguồn bên dưới (lấy từ bài viết gốc) vào một tệp văn bản, lưu với đuôi .lsp.

Cách dùng

  1. Chép mã nguồn, lưu thành tệp 181975_tdt.lsp.
  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 TDT để chạy lisp.

Mã nguồn 181975_tdt.lsp (trích từ bài viết gốc)

(Defun c:TDT()
(setvar "cmdecho" 0)
(setvar "osmode" 0)
(command "osnap" "none")
(if (null am)(setq am "1"))
(Setq temp1 T)
(While temp1
(setq pt (strcat "\nHe so ("am") \<Chon diem>: "))
(Initget "h H")
(setq str (getpoint pt))
(Cond
 ((= str "h") (setq am (getstring (strcat"\nNhap he so <"am"> :"))))
 ((= str "H") (setq am (getstring (strcat"\nNhap he so <"am"> :"))))
  (Progn
 (Setq pt str)
  (setq temp1 nil)
 )
)
)
(setq s 0)
(progn
;  (setq pt (getpoint "\n Chon diem: "))
  	(while pt
  (setq entold (cdr (assoc 5 (entget (entlast)))))
  (command "boundary" pt "")
  (setq entnew (cdr (assoc 5 (entget (entlast)))))
  (if (/= entold entnew)  
(progn
            			(setq entnew (entget (entlast)))
            			(if (assoc 62 entnew)
                       	(setq entnew (subst (cons 62 (+ 3 (cdr (assoc 62 entnew)))) (assoc 62 entnew) entnew))
                       	(setq entnew (append entnew (list (cons 62 (+ 3 (cdr (assoc 62 (tblsearch "layer" (cdr (assoc 8 entnew))))))))))
              			)


            			(entmod entnew)
            			(Command "area" "o" (entlast))
(setq s (+ s (getvar "area")))
   	(setq pt (getpoint "\n Chon diem: "))
(entdel (entlast))
  		)
(progn
(princ "chon diem sai")
(setq pt (getpoint "\n Chon diem: "))
)
  )
)
       	)

(command "osnap" "intersection")
(setq am (atof am))
(setq s (* s am))
(setq point (getpoint "\n Chon diem ghi dien tich: "))
(setq th (getvar "textsize"))
(setq th (getstring (strcat "\nChieu cao chu <"(rtos th)"> :")))
 ;(princ "\nDien tich nhung vung vua chon la: "s)
(command "TEXT" point th 0 (rtos s 2 2))
 (setvar "MODEMACRO" "**CHUC BAN LAM VIEC HIEU QUA** TAILIEUKYTHUAT.COM")        
(princ )
)

Thảo luận gốc

Lisp được chia sẻ trong chủ đề [Nhờ chỉnh sửa] lisp tính tổng diện tích. Xem đúng bài viết #181975 để đọc hướng dẫn và trao đổi thêm.

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