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ái này hay quá, các bác ơi nổ tiếp để em học hỏi với
- Tải lisp
- 331133_test.lsp
Cách dùng
- Tải tệp 331133_test.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 TEST để chạy lisp.
Mã nguồn 331133_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 #331133 để đọc hướng dẫn và trao đổi thêm.