Jump to content

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:

Cách dùng

  1. Tải tệp 56883_scissors.lsp về máy.
  2. 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ẽ.
  3. Gõ lệnh SCISSORS để chạy lisp.

Mã nguồn 56883_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 #56883 để đọc hướng dẫn và trao đổi thêm.

Về Thư viện AutoLisp (trang 13)