Lisp rải đối tượng theo đơờng dẩn.
- yêu cầu 1 : cập nhật.
- yêu cầu 2 : Rải cả điểm đầu và cuối của đường dẫn.
Về mặt lập trình, việc thêm tùy chọn "Rải cả điểm đầu và cuối của đường dẫn (Yes/No):" LISP có thể đáp ứng đuợc. Nhưng theo quan điểm cá nhân tôi, thêm tùy chọn này chỉ làm rối thêm Lisp (trong t/hợp có giao điểm thưc giữa đuờng dẫn và đối tựong lấy giao điểm tại điểm đầu hay điểm cuối).
Do đó trong t/hợp bạn phải dùng Lisp này và muốn "Rải cả điểm đầu và cuối của đường dẫn", vui lòng "vẽ thêm 1 line nối điểm đầu và cuối của đường dẫn" truớc khi chạy lisp này (dĩ nhiên sau đó nhớ xóa line này đi).
(defun c:ATIC(/ ent ov pts ss h num eEnt pick txt); ATIC -> Add Text at Intersect with Curve ;; By : Gia_Bach, www.CadViet.com 2011 ;; (vl-load-com) (command "undo" "be") (setq ov (getvar "cmdecho") ) (setvar "cmdecho" 0) (if (and (setq eEnt (entsel "\nChon Curve :")) (setq ent (car eEnt) pick (trans (cadr eEnt) 1 0)) (wcmatch (cdr (assoc 0 (entget ent))) "*LINE,ARC") (princ "\nChon doi tuong lay giao diem :") (setq ss (ssget (list (cons 0 "*LINE,ARC,CIRCLE,ELLIPSE")))) (setq pts (ent_ss_interpts (setq ent (vlax-ename->vla-object ent) ) ss)) (>(vl-list-length pts)0) ) (progn (or *h* (setq *h* 1)) (initget 6) (setq h (getdist (strcat "\nChieu cao chu <" (rtos *h*) "> :"))) (if h (setq *h* h)) (or *num* (setq *num* 1)) (setq num (getint (strcat "\nGia tri bat dau <" (itoa *num*) "> :"))) (if num (setq *num* num) ) (or spc (setq spc (vla-get-modelspace (vla-get-ActiveDocument (vlax-get-Acad-Object))))) (foreach pt (if (> (vlax-curve-getDistAtPoint ent (vlax-curve-getClosestPointTo ent pick)) (/ (vlax-curve-getDistAtParam ent (vlax-curve-getEndParam ent))2)) (reverse pts) pts) (setq txt (vla-AddText spc (itoa *num*) (vlax-3D-point pt) *h*) *num* (1+ *num*)) (vla-put-alignment txt 10) (vla-put-TextAlignmentPoint txt (vlax-3D-point pt))) (setvar "cmdecho" ov) (command "undo" "e") ) (alert "Khong tim duoc giao diem!")) (princ)) (defun ent_ss_interpts (ent ss / e i intpts lst_pt) ;; By : Gia_Bach, www.CadViet.com 2011 ;; (defun list->3pair (old / new) (while (setq new (cons (list (car old) (cadr old) (caddr old)) new) old (cdddr old))) (reverse new) ) (setq i -1) (while (setq e (ssname ss (setq i (1+ i)))) (if (and (not (equal ent (setq eObj (vlax-Ename->Vla-Object e)))) (setq intpts (vlax-invoke ent 'IntersectWith eObj 0)) ) (foreach pt (list->3pair intpts) (if (not (vl-position pt lst_pt)) (setq lst_pt (cons pt lst_pt)) ))) ) (vl-sort lst_pt '(lambda (x y) (< (vlax-curve-getParamAtPoint ent (vlax-curve-getClosestPointTo ent x)) (vlax-curve-getParamAtPoint ent (vlax-curve-getClosestPointTo ent y))))) )
Cảm ơn anh gia_bach,lisp của an đã làm tốt yêu cầu của em rồi.Nhưng em mong anh có thể kết hợp thêm với lisp của anh Duy vì lúc rải đối tượng em có 2 lựa chọn: 1 là khoảng cách và 2 là tìm giao điểm của các đường giao như lisp của anh.Mong anh và anh Duy cùng các anh khác trên diễn đàn kết hợp 2lisp này giùm em với anh.Em lại được voi đòi tiên rồi.hihi.Cảm ơn anh gia_bach và anh duy nhiều
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 155110_atic.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 ATIC để chạy lisp.
Mã nguồn 155110_atic.lsp (trích từ bài viết gốc)
(defun c:ATIC(/ ent ov pts ss h num eEnt pick txt); ATIC -> Add Text at Intersect with Curve
;; By : Gia_Bach, www.CadViet.com 2011 ;;
(vl-load-com)
(command "undo" "be")
(setq ov (getvar "cmdecho") )
(setvar "cmdecho" 0)
(if (and (setq eEnt (entsel "\nChon Curve :"))
(setq ent (car eEnt) pick (trans (cadr eEnt) 1 0))
(wcmatch (cdr (assoc 0 (entget ent))) "*LINE,ARC")
(princ "\nChon doi tuong lay giao diem :")
(setq ss (ssget (list (cons 0 "*LINE,ARC,CIRCLE,ELLIPSE"))))
(setq pts (ent_ss_interpts (setq ent (vlax-ename->vla-object ent) ) ss))
(>(vl-list-length pts)0) )
(progn
(or *h* (setq *h* 1))
(initget 6)
(setq h (getdist (strcat "\nChieu cao chu <" (rtos *h*) "> :")))
(if h (setq *h* h))
(or *num* (setq *num* 1))
(setq num (getint (strcat "\nGia tri bat dau <" (itoa *num*) "> :")))
(if num (setq *num* num) )
(or spc (setq spc (vla-get-modelspace (vla-get-ActiveDocument (vlax-get-Acad-Object)))))
(foreach pt (if (> (vlax-curve-getDistAtPoint ent (vlax-curve-getClosestPointTo ent pick))
(/ (vlax-curve-getDistAtParam ent (vlax-curve-getEndParam ent))2))
(reverse pts) pts)
(setq txt (vla-AddText spc (itoa *num*) (vlax-3D-point pt) *h*)
*num* (1+ *num*))
(vla-put-alignment txt 10)
(vla-put-TextAlignmentPoint txt (vlax-3D-point pt)))
(setvar "cmdecho" ov)
(command "undo" "e") )
(alert "Khong tim duoc giao diem!"))
(princ))
(defun ent_ss_interpts (ent ss / e i intpts lst_pt)
;; By : Gia_Bach, www.CadViet.com 2011 ;;
(defun list->3pair (old / new)
(while (setq new (cons (list (car old) (cadr old) (caddr old)) new)
old (cdddr old)))
(reverse new) )
(setq i -1)
(while (setq e (ssname ss (setq i (1+ i))))
(if (and
(not (equal ent (setq eObj (vlax-Ename->Vla-Object e))))
(setq intpts (vlax-invoke ent 'IntersectWith eObj 0)) )
(foreach pt (list->3pair intpts)
(if (not (vl-position pt lst_pt))
(setq lst_pt (cons pt lst_pt)) ))) )
(vl-sort lst_pt
'(lambda (x y)
(< (vlax-curve-getParamAtPoint ent (vlax-curve-getClosestPointTo ent x))
(vlax-curve-getParamAtPoint ent (vlax-curve-getClosestPointTo ent y))))) )Thảo luận gốc
Lisp được chia sẻ trong chủ đề [Đã xong] Lisp rải đối tượng theo đơờng dẩn.. Xem đúng bài viết #155110 để đọc hướng dẫn và trao đổi thêm.