Lisp lệnh GETA trong chủ đề “autolisp diện tích giống lệnh area nhưng có thêm mục ghi text ra luôn”
Lisp này chắc phù hợp ý của @nguyen hai son
(defun lstpoint (/ ptemp PT lstp)
(setq lstp (list (setq PT (getpoint "\nPick the first point "))))
(setq ptemp pt)
(while (setq PT (getpoint ptemp "\nPick the next point "))
(grdraw ptemp PT 8 1)
(setq lstp (append lstp (list pt)))
(setq ptemp pt)
)
lstp
)
(defun SetClipBoardText (text / htmlfile result) ; By XShrimp
(if (= 'STR (type text))
(progn
(setq htmlfile (vlax-create-object "htmlfile")
result (vlax-invoke
(vlax-get (vlax-get htmlfile 'ParentWindow)
'ClipBoardData
)
'SetData
"Text"
text
)
)
(vlax-release-object htmlfile)
text
)
)
)
(defun GetArea (lst )
(/ (apply
'+
(mapcar '(lambda (a b) (- (* (car b) (cadr a)) (* (car a) (cadr b))))
lst
(cons (last lst) lst)
)
)
2
)
)
(defun c:getA (/)
(command "undo" "be")
(acet-sysvar-set '("cmdecho" 0 "osmode" 545))
(SetClipBoardText (rtos (abs (GetArea (lstpoint)))))
(command "_pasteclip")
(acet-sysvar-restore)
(redraw)
(command "undo" "en")
(princ "\nOk")
)
- Tải lisp
- 446623_geta.lsp
Cách dùng
- Tải tệp 446623_geta.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 GETA để chạy lisp.
Mã nguồn 446623_geta.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/180205-autolisp-di%E1%BB%87n-t%C3%ADch-gi%E1%BB%91ng-l%E1%BB%87nh-area-nh%C6%B0ng-c%C3%B3-th%C3%AAm-m%E1%BB%A5c-ghi-text-ra-lu%C3%B4n/?tab=comments#comment-446574
(defun lstpoint (/ ptemp PT lstp)
(setq lstp (list (setq PT (getpoint "\nPick the first point "))))
(setq ptemp pt)
(while (setq PT (getpoint ptemp "\nPick the next point "))
(grdraw ptemp PT 8 1)
(setq lstp (append lstp (list pt)))
(setq ptemp pt)
)
lstp
)
(defun SetClipBoardText (text / htmlfile result) ; By XShrimp
(if (= 'STR (type text))
(progn
(setq htmlfile (vlax-create-object "htmlfile")
result (vlax-invoke
(vlax-get (vlax-get htmlfile 'ParentWindow)
'ClipBoardData
)
'SetData
"Text"
text
)
)
(vlax-release-object htmlfile)
text
)
)
)
(defun GetArea (lst )
(/ (apply
'+
(mapcar '(lambda (a b) (- (* (car b) (cadr a)) (* (car a) (cadr b))))
lst
(cons (last lst) lst)
)
)
2
)
)
(defun c:getA (/)
(command "undo" "be")
(acet-sysvar-set '("cmdecho" 0 "osmode" 545))
(SetClipBoardText (rtos (abs (GetArea (lstpoint)))))
(command "_pasteclip")
(acet-sysvar-restore)
(redraw)
(command "undo" "en")
(princ "\nOk")
)Thảo luận gốc
Lisp được chia sẻ trong chủ đề autolisp diện tích giống lệnh area nhưng có thêm mục ghi text ra luôn. Xem đúng bài viết #446623 để đọc hướng dẫn và trao đổi thêm.