Jump to content

Lisp lệnh TRR trong chủ đề “Help .......nhờ các anh viết lisp ....về lệnh trim”

Lâu ngày không viết nên ngứa ngáy tay chân. 

Lisp của bạn đây : Lệnh TRR


(defun c:trr(/ e1 e2 i en)
(defun Tue-geom-divpt (p1 p2 k)
    (polar p1 (angle p1 p2) (* (distance p1 p2) k))
)
(defun Tue-list-tach (lst count / i j Lst-tinh Reslis)
 ;;;;;Ex: (Tue-list-tach '(1 5 4 6 3 5) 2)--> ((1 5) (4 6) (3 5))
 ;;;;;;;;;(Tue-list-tach '(1 5 4 6 3 5) 3)--> ((1 5 4) (6 3 5))
 ;;;;;;;;;(Tue-list-tach '(1 5 4 6 3 5) 5)--> nil
   (setq i 0 j 0)
   (while (and (< i (/ (length lst) count)) (= (rem (length lst) count) 0))
    (Repeat count
      (setq Lst-tinh (append Lst-tinh (list (nth j lst)) ))
      (setq j (1+ j))  
     )
         (setq Reslis (append Reslis (list Lst-tinh))
           Lst-tinh nil)
     (setq i (1+ i))
    )
 Reslis
)
(defun Tue-geom-inters(e1 e2 flag / Lst_tong Lst);;;Tue-list-tach
 ;;; flag= 0 : acExtendNone Does not extend either object.
 ;;; flag= 1 : acExtendThisEntity Extends the base object.
 ;;; flag= 2 : acExtendOtherEntity Extends the object passed as an argument.
 ;;; flag= 3 : acExtendBoth  Extends both objects.
;;Ex: (Tue-geom-inters (ssname (TUE-SS-ENTSEL '((0 . "*LINE,ARC,CIRCLE,ELLIPSE")) "\npick chon doi tuong thu 1 :") 0)
;;;;;;;;;;;;;;;;;;;;;;;(ssname (TUE-SS-ENTSEL '((0 . "*LINE,ARC,CIRCLE,ELLIPSE")) "\npick chon doi tuong thu 2 :") 0) 0)
  (if (= (type e1) 'ENAME) (setq e1 (vlax-ename->vla-object e1)))
  (if (= (type e2) 'ENAME) (setq e2 (vlax-ename->vla-object e2)))
  (Tue-list-tach (vlax-invoke e1 'IntersectWith e2 flag) 3)
)
;;;main
  (setq e1 (car(entsel "\n Chon duong cat 1 :")))
  (setq e2 (car(entsel "\n Chon duong cat 2 :")) i -1)
  (if (setq ss (ssget '((0 . "*LINE,ARC"))))
  (while (setq en (ssname ss (setq i (1+ i))))
    (if (and (= (length (setq p1 (Tue-geom-inters e1 en 0))) 1) (= (length (setq p2 (Tue-geom-inters e2 en 0))) 1))
    (command "._trim" e1 e2 ""
         (Tue-geom-divpt (car p1)  (car p2) 0.5) "")
  )
)
)
  )

 

Cách dùng

  1. Tải tệp 437026_trr.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 TRR để chạy lisp.

Mã nguồn 437026_trr.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/176417-help-nh%E1%BB%9D-c%C3%A1c-anh-vi%E1%BA%BFt-lisp-v%E1%BB%81-l%E1%BB%87nh-trim/

(defun c:trr(/ e1 e2 i en)
(defun Tue-geom-divpt (p1 p2 k)
    (polar p1 (angle p1 p2) (* (distance p1 p2) k))
)
(defun Tue-list-tach (lst count / i j Lst-tinh Reslis)
 ;;;;;Ex: (Tue-list-tach '(1 5 4 6 3 5) 2)--> ((1 5) (4 6) (3 5))
 ;;;;;;;;;(Tue-list-tach '(1 5 4 6 3 5) 3)--> ((1 5 4) (6 3 5))
 ;;;;;;;;;(Tue-list-tach '(1 5 4 6 3 5) 5)--> nil
   (setq i 0 j 0)
   (while (and (< i (/ (length lst) count)) (= (rem (length lst) count) 0))
    (Repeat count
      (setq Lst-tinh (append Lst-tinh (list (nth j lst)) ))
      (setq j (1+ j))  
     )
         (setq Reslis (append Reslis (list Lst-tinh))
           Lst-tinh nil)
     (setq i (1+ i))
    )
 Reslis
)
(defun Tue-geom-inters(e1 e2 flag / Lst_tong Lst);;;Tue-list-tach
 ;;; flag= 0 : acExtendNone Does not extend either object.
 ;;; flag= 1 : acExtendThisEntity Extends the base object.
 ;;; flag= 2 : acExtendOtherEntity Extends the object passed as an argument.
 ;;; flag= 3 : acExtendBoth  Extends both objects.
;;Ex: (Tue-geom-inters (ssname (TUE-SS-ENTSEL '((0 . "*LINE,ARC,CIRCLE,ELLIPSE")) "\npick chon doi tuong thu 1 :") 0)
;;;;;;;;;;;;;;;;;;;;;;;(ssname (TUE-SS-ENTSEL '((0 . "*LINE,ARC,CIRCLE,ELLIPSE")) "\npick chon doi tuong thu 2 :") 0) 0)
  (if (= (type e1) 'ENAME) (setq e1 (vlax-ename->vla-object e1)))
  (if (= (type e2) 'ENAME) (setq e2 (vlax-ename->vla-object e2)))
  (Tue-list-tach (vlax-invoke e1 'IntersectWith e2 flag) 3)
)
;;;main
  (setq e1 (car(entsel "\n Chon duong cat 1 :")))
  (setq e2 (car(entsel "\n Chon duong cat 2 :")) i -1)
  (if (setq ss (ssget '((0 . "*LINE,ARC"))))
  (while (setq en (ssname ss (setq i (1+ i))))
    (if (and (= (length (setq p1 (Tue-geom-inters e1 en 0))) 1) (= (length (setq p2 (Tue-geom-inters e2 en 0))) 1))
    (command "._trim" e1 e2 ""
         (Tue-geom-divpt (car p1)  (car p2) 0.5) "")
  )
)
)
  )

Thảo luận gốc

Lisp được chia sẻ trong chủ đề Help .......nhờ các anh viết lisp ....về lệnh trim. Xem đúng bài viết #437026 để đọc hướng dẫn và trao đổi thêm.

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