Lisp lệnh HOGA trong chủ đề “giúp e lisp copy đối tượng cách đều nhau (không giống ME hay Div đâu)”
file mới nhất đây, mời các ae ra tay giúp dùmhttp://www.mediafire.com/?0h7ywyo99wi0w1w
Mọi ghi chú đều có trong file trên. Mọi người xem giúp cái . Thanks
Nếu đường không cong lắm thì cống đặt thẳng => kc hố ga không đổi là hợp lý
Bạn dùng lisp này (chưa align hố ga)
copy 1 block vào đầu đường cong bạn muốn rồi đấnh lệnh
Tham khảo lisp này (bài viết số #1518) để align hố ga theo đường cong
https://www.cadviet.com/forum/index.php?s=&...st&p=102888
(defun C:hoga ( / bl pl ci l lo li b pt p1 p2 ptl sn om)
(defun get_interpts (obj1 obj2 / iplist)
(if (not (vl-catch-all-error-p
(setq iplist (vl-catch-all-apply
'vlax-safearray->list
(list
(vlax-variant-value
(vla-intersectwith obj1 obj2 acextendnone)
))))))
iplist
)
)
;;
(while (not bl)
(progn
(princ "\nChon block :")
(setq bl (ssget ":S" '((0 . "Insert"))))
))
(while (not pl)
(progn
(princ "\nChon duong chuan :")
(setq pl (ssget ":S" '((0 . "LWPOLYLINE"))))
))
(setq om (getvar "OSMODE")) (setvar "OSMODE" 0)
(setq bl (ssname bl 0) pl (vlax-ename->vla-object (ssname pl 0)) pt (cdr (assoc 10 (entget bl))))
(setq l (getdist "\nKhoang cach:") p1 pt p2 (vlax-curve-getClosestPointTo pl pt))
(setq lo (vlax-curve-getDistAtPoint pl p2))
(setq sn
(if (> 0.5 ( / (vlax-curve-getParamAtPoint pl p2)(vlax-curve-getEndParam pl))) 1 -1 ))
(while (not B )
(progn
(command "_Circle" p1 l)
(setq ci (vlax-ename->vla-object (entlast)))
(setq ptl (get_interpts pl ci) b T)
(command "_Erase" "l" "")
(while ptl
(setq p2 (list (car ptl) (cadr ptl) (caddr ptl)))
(setq li (vlax-curve-getDistAtPoint pl p2))
(setq ptl (cdddr ptl))
(if (>(* sn (- li lo)) (/ l 2))
(progn
(command "copy" bl "" pt p2)
(setq ptl nil b nil p1 p2 lo li)
)
)
)
;(setq)
) )
(setvar "OSMODE" om)
)
- Tải lisp
- 103524_hoga.lsp
Cách dùng
- Tải tệp 103524_hoga.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 HOGA để chạy lisp.
Mã nguồn 103524_hoga.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/22604-gi%C3%BAp-e-lisp-copy-%C4%91%E1%BB%91i-t%C6%B0%E1%BB%A3ng-c%C3%A1ch-%C4%91%E1%BB%81u-nhau-kh%C3%B4ng-gi%E1%BB%91ng-me-hay-div-%C4%91%C3%A2u/
(defun C:hoga ( / bl pl ci l lo li b pt p1 p2 ptl sn om)
(defun get_interpts (obj1 obj2 / iplist)
(if (not (vl-catch-all-error-p
(setq iplist (vl-catch-all-apply
'vlax-safearray->list
(list
(vlax-variant-value
(vla-intersectwith obj1 obj2 acextendnone)
))))))
iplist
)
)
;;
(while (not bl)
(progn
(princ "\nChon block :")
(setq bl (ssget ":S" '((0 . "Insert"))))
))
(while (not pl)
(progn
(princ "\nChon duong chuan :")
(setq pl (ssget ":S" '((0 . "LWPOLYLINE"))))
))
(setq om (getvar "OSMODE")) (setvar "OSMODE" 0)
(setq bl (ssname bl 0) pl (vlax-ename->vla-object (ssname pl 0)) pt (cdr (assoc 10 (entget bl))))
(setq l (getdist "\nKhoang cach:") p1 pt p2 (vlax-curve-getClosestPointTo pl pt))
(setq lo (vlax-curve-getDistAtPoint pl p2))
(setq sn
(if (> 0.5 ( / (vlax-curve-getParamAtPoint pl p2)(vlax-curve-getEndParam pl))) 1 -1 ))
(while (not B )
(progn
(command "_Circle" p1 l)
(setq ci (vlax-ename->vla-object (entlast)))
(setq ptl (get_interpts pl ci) b T)
(command "_Erase" "l" "")
(while ptl
(setq p2 (list (car ptl) (cadr ptl) (caddr ptl)))
(setq li (vlax-curve-getDistAtPoint pl p2))
(setq ptl (cdddr ptl))
(if (>(* sn (- li lo)) (/ l 2))
(progn
(command "copy" bl "" pt p2)
(setq ptl nil b nil p1 p2 lo li)
)
)
)
;(setq)
) )
(setvar "OSMODE" om)
)
Thảo luận gốc
Lisp được chia sẻ trong chủ đề giúp e lisp copy đối tượng cách đều nhau (không giống ME hay Div đâu). Xem đúng bài viết #103524 để đọc hướng dẫn và trao đổi thêm.