Lisp lệnh SCISSORS trong chủ đề “Cad có lênh này không?”
* Với AutoCAD thì dùng Break at point có trên thanh Modify:+ Chọn đối tượng
+ Chọn giao điểm
* Với LISP:
+ Lệnh SCISSORS
+ Chọn giao điểm
+ Chọn đối tượng
(Bác nào có thể giúp sửa Lisp này để có thể select được nhiều đối tượng. Thx)
Lisp sưu tầm:
(defun C:SCISSORS( / pt1 bpt1 bpt2 ss1 dist1 ent1 centrecercle) ;;make it quiet (setvar "cmdecho" 0) ;;first, get the breaking point (setq pt1 (getpoint "Give me the break point... ")) ;;point where to break ;;now, check if there's more than one object under that point (setq ss1 (selectfrompoint pt1)) ;;if there's more than 1 object under point, ask to select, else use existing point (if (> (sslength ss1) 1) (progn ;;then (princ "DISAMBIGUATION : pick the object to break...") (setq ent1 (entsel)) (setq ent1n (car ent1)) ;; e-name of ent1 (setq bpt1 (cadr ent1)) ;; point on ent to break ) (progn ;;else (setq ent1n (ssname ss1 0));;store into an entity (can be useful further) (setq bpt1 pt1) ;; point on ent to break ) ) ;;but if it's a circle (thus usually unbreakable)... (if (= (cdr (assoc 0 (entget ent1n))) "CIRCLE") ;;then replace the circle by 2 arcs joining at the break point (progn (princ "It's a circle !") (setq centrecercle (cdr (assoc 10 (entget ent1n)))) (command "_arc" "_c" centrecercle pt1 "_a" "180") (command "_arc" "_c" centrecercle pt1 "_a" "-180") (entdel ent1n) ) ;;else perform a normal break (progn (command "_break" bpt1 "_f" pt1 pt1) ) ) ;;restore cmdecho (setvar "cmdecho" 1) ;;end quietly (princ) ) ;;--- this function makes a selection set of entities beneath a point (defun selectfrompoint (bpt1 / dist1 ss1) (setq dist1 (/ (getvar "viewsize") 200)) ;; set a distance equal to 1/200-th of view height (setq ss1 ;;select by fence around point (ssget "_F" (list (list (+ (car bpt1) dist1) (+ (cadr bpt1) dist1) 0) (list (- (car bpt1) dist1) (- (cadr bpt1) dist1) 0) ) ) );; setq ss1 ss1 )
Đây là Lisp Tue_nv đã viết và chỉnh sửa lại một chút :
- Lệnh Brt
- Chọn đường cắt bằng cách chọn 2 điểm
- Chọn đối tượng
- Lisp sẽ break tại điểm giao của đường cắt với đối tượng
Giống như cách chọn đối tượng theo kiểu F(Fence)
(Defun c:brt(/ aL bL cL dL eL sL ss n i) (vl-load-com) (prompt "\n Chon duong cat bang cach chon diem thu nhat va diem thu hai :") (setq aL (getpoint "\n Chon diem thu nhat :")) (setq bL (getpoint aL "\n Chon diem thu hai :")) (Prompt "\n Chon doi tuong Line can break tai 1 diem :") (Setq ss (ssget '((0 . "LINE,LWPOLYLINE")))) (Setq n (sslength ss) i 0) (while ((setq sL (ssname ss i)) (setq cL (vlax-curve-getStartPoint sL)) (setq dL (vlax-curve-getEndPoint sL)) (setq eL (inters aL bL cL dL T)) (if (= eL nil) (setq i (1+ i))) (if (/= eL nil) (progn (Command "_Break" sL eL "@") (setq i (1+ i)) ) ) ) (sssetfirst ss ss) (Princ) )
Các bạn có thể tham khoả thêm bài viết : Hoi ve lenh Break
Chúc thành công :(
- Tải lisp
- 57293_scissors.lsp
Cách dùng
- Tải tệp 57293_scissors.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 SCISSORS để chạy lisp.
Mã nguồn 57293_scissors.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/10318-cad-c%C3%B3-l%C3%AAnh-n%C3%A0y-kh%C3%B4ng/
(defun C:SCISSORS( / pt1 bpt1 bpt2 ss1 dist1 ent1 centrecercle)
;;make it quiet
(setvar "cmdecho" 0)
;;first, get the breaking point
(setq pt1 (getpoint "Give me the break point... ")) ;;point where to break
;;now, check if there's more than one object under that point
(setq ss1 (selectfrompoint pt1))
;;if there's more than 1 object under point, ask to select, else use existing point
(if (> (sslength ss1) 1)
(progn ;;then
(princ "DISAMBIGUATION : pick the object to break...")
(setq ent1 (entsel))
(setq ent1n (car ent1)) ;; e-name of ent1
(setq bpt1 (cadr ent1)) ;; point on ent to break
)
(progn ;;else
(setq ent1n (ssname ss1 0));;store into an entity (can be useful further)
(setq bpt1 pt1) ;; point on ent to break
)
)
;;but if it's a circle (thus usually unbreakable)...
(if
(= (cdr (assoc 0 (entget ent1n))) "CIRCLE")
;;then replace the circle by 2 arcs joining at the break point
(progn
(princ "It's a circle !")
(setq centrecercle (cdr (assoc 10 (entget ent1n))))
(command "_arc" "_c" centrecercle pt1 "_a" "180")
(command "_arc" "_c" centrecercle pt1 "_a" "-180")
(entdel ent1n)
)
;;else perform a normal break
(progn
(command "_break" bpt1 "_f" pt1 pt1)
)
)
;;restore cmdecho
(setvar "cmdecho" 1)
;;end quietly
(princ)
)
;;--- this function makes a selection set of entities beneath a point
(defun selectfrompoint (bpt1 / dist1 ss1)
(setq dist1 (/ (getvar "viewsize") 200)) ;; set a distance equal to 1/200-th of view height
(setq ss1 ;;select by fence around point
(ssget "_F"
(list
(list (+ (car bpt1) dist1) (+ (cadr bpt1) dist1) 0)
(list (- (car bpt1) dist1) (- (cadr bpt1) dist1) 0)
)
)
);; setq ss1
ss1
)Thảo luận gốc
Lisp được chia sẻ trong chủ đề Cad có lênh này không?. Xem đúng bài viết #57293 để đọc hướng dẫn và trao đổi thêm.