Jump to content

Lisp lệnh TEST trong chủ đề “Một số hàm con VL- hữu ích”

Đánh lệnh vlide, bấm f1, vào ActiveX and VBA reference > Objects > Line object. Bên phần Properties bạn thấy 1 dãy. Tất cả những cái đó đều có thể ghép với vla-get- để biết thuộc tính của line, nhưng chỉ 1 số có thể ghép với vla-put- để thay đổi thuộc tính. Muốn biết cái nào dùng dc với vla-put- thi bạn cứ ghép thử, thấy cái nào chuyển màu xanh là ok, còn màu đen là not ok.

Dưới đây là lsp test, tôi chỉ lấy vài cái prop đẻ thử thôi. bạn vẽ 1 line rồi chạy lsp.

 

(defun c:test ()
  (defun v2p (a)  (vlax-safearray->list (vlax-variant-value a)))
  (setq a (car (entsel "\nChon Line:"))
obj (vlax-ename->vla-object a))
  (alert  (strcat "\nAngle : " (rtos (vla-get-Angle obj))
 "\nDelta : " (vl-prin1-to-string (v2p (vla-get-Delta obj)))
 "\nLength : " (rtos (vla-get-Length obj))
 "\nStartPoint : " (vl-prin1-to-string (setq dd (v2p (vla-get-StartPoint obj))))
 "\nEndPoint : " (vl-prin1-to-string (setq dc (v2p (vla-get-EndPoint obj))))
 "\nLayer : " (vla-get-Layer obj)
 "\nLinetype : " (vla-get-Linetype obj)
 "\nLinetypeScale : " (rtos (vla-get-LinetypeScale obj))
 "\nLineweight : " (rtos (vla-get-Lineweight obj))      
   ))
  (vla-put-StartPoint obj (vlax-3d-point (polar dd 0 1)))
  (vla-put-EndPoint obj (vlax-3d-point (polar dc 0 -1)))
  (alert  (strcat "\nNew StartPoint : " (vl-prin1-to-string  (v2p (vla-get-StartPoint obj)))
 "\nNew EndPoint : " (vl-prin1-to-string  (v2p (vla-get-EndPoint obj)))))
)

Cách dùng

  1. Tải tệp 313774_test.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 TEST để chạy lisp.

Mã nguồn 313774_test.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/10666-m%E1%BB%99t-s%E1%BB%91-h%C3%A0m-con-vl-h%E1%BB%AFu-%C3%ADch/
(defun c:test ()
  (defun v2p (a)  (vlax-safearray->list (vlax-variant-value a)))
  (setq a (car (entsel "\nChon Line:"))
obj (vlax-ename->vla-object a))
  (alert  (strcat "\nAngle : " (rtos (vla-get-Angle obj))
 "\nDelta : " (vl-prin1-to-string (v2p (vla-get-Delta obj)))
 "\nLength : " (rtos (vla-get-Length obj))
 "\nStartPoint : " (vl-prin1-to-string (setq dd (v2p (vla-get-StartPoint obj))))
 "\nEndPoint : " (vl-prin1-to-string (setq dc (v2p (vla-get-EndPoint obj))))
 "\nLayer : " (vla-get-Layer obj)
 "\nLinetype : " (vla-get-Linetype obj)
 "\nLinetypeScale : " (rtos (vla-get-LinetypeScale obj))
 "\nLineweight : " (rtos (vla-get-Lineweight obj))      
   ))
  (vla-put-StartPoint obj (vlax-3d-point (polar dd 0 1)))
  (vla-put-EndPoint obj (vlax-3d-point (polar dc 0 -1)))
  (alert  (strcat "\nNew StartPoint : " (vl-prin1-to-string  (v2p (vla-get-StartPoint obj)))
 "\nNew EndPoint : " (vl-prin1-to-string  (v2p (vla-get-EndPoint obj)))))
)

Thảo luận gốc

Lisp được chia sẻ trong chủ đề Một số hàm con VL- hữu ích. Xem đúng bài viết #313774 để đọc hướng dẫn và trao đổi thêm.

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