Nhờ Anh Em Tạo Lisp Vẽ Đường Giao 2 Đường Thẳng
Bởi hiepttrLệnh: DG
Mì ăn liền cho bạn đây ^^
(defun c:DG( / lst_va old d1 d2 int_p sta_p end_p sta_p2 end_p2)
(setq lst_va '("osmode" "cmdecho"))
(setq old (mapcar 'getvar lst_va))
(mapcar 'setvar lst_va '(0 0))
;-------------
(setq d1 (entsel "\n Pick chon D1: ")
d2 (entsel "\n Pick chon D2: ")
)
(if (and d1 d2)
(progn
(setq d1 (car d1)
d2 (car d2)
)
(if (setq int_p (H:inter-group3 d1 d2))
(progn
(setq int_p (car int_p)
sta_p (vlax-curve-getPointAtParam d1 0)
end_p (vlax-curve-getPointAtParam d1 (vlax-curve-getEndParam d1))
sta_p2 (vlax-curve-getPointAtParam d2 0)
end_p2 (vlax-curve-getPointAtParam d2 (vlax-curve-getEndParam d2))
;sta_p (vlax-safearray->list (variant-value (vla-get-StartPoint d1)))
;end_p (vlax-safearray->list (variant-value (vla-get-EndPoint d1)))
)
(if (< (distance int_p sta_p) (distance int_p end_p)) (setq end_p sta_p))
(if (< (distance int_p sta_p2) (distance int_p end_p2)) (setq end_p2 sta_p2))
(MakeLine int_p (mid int_p end_p) "4")
(MakeLine int_p (mid int_p end_p2) "4")
)
(princ "\n 02 thang nay khong giao nhau ma ^|^ ***")
)
)
(princ "\n Pick truot roi ^|^ ***")
)
;;xong tra ve:
(mapcar 'setvar lst_va old)
(princ)
)
;;;;==============================================================
(defun H:inter-group3(ob1 ob2 / modul res)
(setq ob1 (vlax-ename->vla-object ob1)
ob2 (vlax-ename->vla-object ob2)
)
(cond
((null (setq modul (vlax-invoke ob1 'intersectwith ob2 acExtendBoth))) nil)
((= (length modul) 3) (list modul))
(t
(while (> (length modul) 0)
(setq res (cons (list (car modul) (cadr modul) (caddr modul)) res)
modul (cdddr modul)
)
)
(reverse res)
)
)
)
;================
(defun MakeLine (PT1 PT2 Layer)
(entmakex (list '(0 . "LINE")
(cons 8 (if Layer Layer (getvar "Clayer")))
(cons 10 PT1) (cons 11 PT2)
)
)
)
;=======
(defun mid (p1 p2) (mapcar '* (mapcar '+ p1 p2) '(0.5 0.5 0.5)))
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
- Chép mã nguồn, lưu thành tệp 421918_dg.lsp.
- 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 DG để chạy lisp.
Thảo luận gốc
Bài viết gốc #421918 không còn trên diễn đàn.