Jump to content

Lisp lệnh HA trong chủ đề “Nhờ Các Cao Thủ Giúp Mình Thêm Point Vào Giao Điểm Các Pline”

Này bạn!

(defun C:HA(/ ss ln lst)
 (defun #Inter:1SS(ss / a b i j l)
  (repeat (setq i (sslength ss))
   (setq a (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
   (repeat (setq j i)
    (setq b (vlax-ename->vla-object (ssname ss (setq j (1- j)))) l (cons (#Inter:2Obj a b acExtendNone) l))))
  (apply 'append (reverse l)))
 (defun #Inter:2Obj(obj1 obj2 flag / l r)
  (setq l (vlax-invoke obj1 'intersectwith obj2 flag))
  (repeat (/ (length l) 3)
   (setq r (cons (list (car l) (cadr l) (caddr l)) r) l (cdddr l)))
  (reverse r))
 (defun MPoint (pt) (entmake (list (cons 0 "POINT") (cons 10 pt))))
 (princ "\nChon cac Pline...")
 (if
  (and
   (setq ss (ssget '((0 . "*line"))))
   (setq ln (car (entsel "\nChon Line de chieu hoac move: "))))
  (progn 
   (initget "C M")
   (setq wd (getkword "\nChon hinh thuc [Chieu/Move] <M>: "))
   (setq lst (#Inter:1SS ss))
   (cond
    ((or (= wd "M") (not wd)) (mapcar '(lambda(pt) (Mpoint (vlax-curve-getClosestPointTo ln pt))) lst))
    ((= wd "C") (mapcar '(lambda(pt) (Mpoint pt) (Mpoint (vlax-curve-getClosestPointTo ln pt))) lst)))))
 (princ))

Cách dùng

  1. Tải tệp 405712_ha.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 HA để chạy lisp.

Mã nguồn 405712_ha.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/165086-nh%E1%BB%9D-c%C3%A1c-cao-th%E1%BB%A7-gi%C3%BAp-m%C3%ACnh-th%C3%AAm-point-v%C3%A0o-giao-%C4%91i%E1%BB%83m-c%C3%A1c-pline/
(defun C:HA(/ ss ln lst)
 (defun #Inter:1SS(ss / a b i j l)
  (repeat (setq i (sslength ss))
   (setq a (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
   (repeat (setq j i)
    (setq b (vlax-ename->vla-object (ssname ss (setq j (1- j)))) l (cons (#Inter:2Obj a b acExtendNone) l))))
  (apply 'append (reverse l)))
 (defun #Inter:2Obj(obj1 obj2 flag / l r)
  (setq l (vlax-invoke obj1 'intersectwith obj2 flag))
  (repeat (/ (length l) 3)
   (setq r (cons (list (car l) (cadr l) (caddr l)) r) l (cdddr l)))
  (reverse r))
 (defun MPoint (pt) (entmake (list (cons 0 "POINT") (cons 10 pt))))
 (princ "\nChon cac Pline...")
 (if
  (and
   (setq ss (ssget '((0 . "*line"))))
   (setq ln (car (entsel "\nChon Line de chieu hoac move: "))))
  (progn 
   (initget "C M")
   (setq wd (getkword "\nChon hinh thuc [Chieu/Move] <M>: "))
   (setq lst (#Inter:1SS ss))
   (cond
    ((or (= wd "M") (not wd)) (mapcar '(lambda(pt) (Mpoint (vlax-curve-getClosestPointTo ln pt))) lst))
    ((= wd "C") (mapcar '(lambda(pt) (Mpoint pt) (Mpoint (vlax-curve-getClosestPointTo ln pt))) lst)))))
 (princ))

Thảo luận gốc

Lisp được chia sẻ trong chủ đề Nhờ Các Cao Thủ Giúp Mình Thêm Point Vào Giao Điểm Các Pline. Xem đúng bài viết #405712 để đọc hướng dẫn và trao đổi thêm.

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