Lisp lệnh TMP trong chủ đề “Nhờ viết lisp chia Line hoặc Polyline thành nhiều đoạn Polyline”
Bạn dùng cái này. Chỉ dùng với pline không đoạn cong.
(defun c:tmp() (vl-load-com) (defun ints (o1 o2 / l0 l) (setq l (vlax-Invoke (vlax-EName->vla-Object o1) "IntersectWith" (vlax-EName->vla-Object o2) acExtendBoth) l0 nil) (while l (setq l0 (append l0 (list (list (car l) (cadr l) (caddr l)))) l (cdddr l))) l0 ) (defun themdinh (v pt / entg li ptl entg1 ) (vla-addVertex (setq obj (vlax-ename->vla-object v)) (1+ (fix (setq ptp (vlax-curve-getparamatpoint obj (vlax-curve-getClosestPointTo obj pt))))) (vlax-make-variant (vlax-safearray-fill (vlax-make-safearray vlax-vbdouble (cons 0 1)) (list (car (vlax-curve-getpointatparam obj ptp)) (cadr (vlax-curve-getpointatparam obj ptp))) ) ) ) ) ;;; (command "undo" "be") (setq ent (car (entsel "\nChon Line/Polyline bi cat:"))) (cond ((= (cdr (assoc 0 (entget ent))) "POLYLINE") (command "convertpoly" "L" ent "")) ((= (cdr (assoc 0 (entget ent))) "LINE") (command "pedit" ent "y" "" "") (setq ent (entlast)))) (prompt "\nChon cac Line/Polyline de cat:") (mapcar '(lambda(x) (mapcar '(lambda(y) (themdinh ent y)) (ints ent x))) (vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget '((0 . "LINE,*POLYLINE"))))))) (command "undo" "e") (princ) )
- Tải lisp
- 298794_tmp.lsp
Cách dùng
- Tải tệp 298794_tmp.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 TMP để chạy lisp.
Mã nguồn 298794_tmp.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/103501-nh%E1%BB%9D-vi%E1%BA%BFt-lisp-chia-line-ho%E1%BA%B7c-polyline-th%C3%A0nh-nhi%E1%BB%81u-%C4%91o%E1%BA%A1n-polyline/?tab=comments
(defun c:tmp()
(vl-load-com)
(defun ints (o1 o2 / l0 l)
(setq l (vlax-Invoke (vlax-EName->vla-Object o1) "IntersectWith" (vlax-EName->vla-Object o2) acExtendBoth)
l0 nil)
(while l
(setq l0 (append l0 (list (list (car l) (cadr l) (caddr l))))
l (cdddr l)))
l0
)
(defun themdinh (v pt / entg li ptl entg1 )
(vla-addVertex (setq obj (vlax-ename->vla-object v))
(1+ (fix (setq ptp (vlax-curve-getparamatpoint obj (vlax-curve-getClosestPointTo obj pt)))))
(vlax-make-variant
(vlax-safearray-fill
(vlax-make-safearray vlax-vbdouble (cons 0 1))
(list (car (vlax-curve-getpointatparam obj ptp)) (cadr (vlax-curve-getpointatparam obj ptp)))
)
)
)
)
;;;
(command "undo" "be")
(setq ent (car (entsel "\nChon Line/Polyline bi cat:")))
(cond ((= (cdr (assoc 0 (entget ent))) "POLYLINE") (command "convertpoly" "L" ent ""))
((= (cdr (assoc 0 (entget ent))) "LINE") (command "pedit" ent "y" "" "") (setq ent (entlast))))
(prompt "\nChon cac Line/Polyline de cat:")
(mapcar '(lambda(x) (mapcar '(lambda(y) (themdinh ent y)) (ints ent x)))
(vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget '((0 . "LINE,*POLYLINE")))))))
(command "undo" "e") (princ)
)Thảo luận gốc
Lisp được chia sẻ trong chủ đề Nhờ viết lisp chia Line hoặc Polyline thành nhiều đoạn Polyline. Xem đúng bài viết #298794 để đọc hướng dẫn và trao đổi thêm.