Jump to content

Lisp xuất-nhập toạ độ

+Lệnh IP dùng để insert các Points tại các giao điểm của các Line/Pline/Spline (trên mặt phằng XY) sau khi dùng mouse quét qua các objects.

Lisp do Trưởng lão Ssg viết:

 

;;;-----------------------------------------------------
(defun ss2ent (ss / i Le e) ;;;Convert ss to list of ename
(setq i 0)
(repeat (sslength ss)
(setq
e (ssname ss i)
Le (append Le (list e))
i (1+ i)
)
)
Le
)
;;;-----------------------------------------------------
(defun Inters (e1 e2 / ob1 ob2 g L i kq)
(vl-load-com)
(setq
ob1 (vlax-ename->vla-object e1)
ob2 (vlax-ename->vla-object e2)
g (vlax-variant-value (vla-IntersectWith ob1 ob2 acExtendNone))
)
(if (/= (vlax-safearray-get-u-bound g 1) -1) (setq L (vlax-safearray->list g)))
(setq i 0)
(repeat (/ (length L) 3)
(setq kq (append (list (list (nth i L) (nth (+ i 1) L) (nth (+ i 2) L))) kq))
(setq i (+ i 3))
)
kq
)
;;;-----------------------------------------------------
(defun C:IP ( / Le e0 e Lp p) ;;;Intersection Points
(setq Le (ss2ent (ssget '((0 . "LINE,POLYLINE,LWPOLYLINE,SPLINE")))))
(repeat (1- (length Le))
(setq Le (vl-remove (setq e0 (car Le)) Le))
(foreach e Le (setq Lp (append Lp (inters e0 e))))
)
(foreach p Lp (entmake (list (cons 0 "POINT") (cons 10 (list (car p) (cadr p) 0.0)))))
(princ)
)
;;;-----------------------------------------------------

Bác ơi có thể phát triển lisp này để đếm số lượng điểm point được không nhỉ?

Cách dùng

  1. Tải tệp 411129_ip.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 IP để chạy lisp.

Mã nguồn 411129_ip.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/9019-%C4%91%C3%A3-xong-lisp-xu%E1%BA%A5t-nh%E1%BA%ADp-to%E1%BA%A1-%C4%91%E1%BB%99/?page=3
;;;-----------------------------------------------------
(defun ss2ent (ss / i Le e) ;;;Convert ss to list of ename
(setq i 0)
(repeat (sslength ss)
(setq
e (ssname ss i)
Le (append Le (list e))
i (1+ i)
)
)
Le
)
;;;-----------------------------------------------------
(defun Inters (e1 e2 / ob1 ob2 g L i kq)
(vl-load-com)
(setq
ob1 (vlax-ename->vla-object e1)
ob2 (vlax-ename->vla-object e2)
g (vlax-variant-value (vla-IntersectWith ob1 ob2 acExtendNone))
)
(if (/= (vlax-safearray-get-u-bound g 1) -1) (setq L (vlax-safearray->list g)))
(setq i 0)
(repeat (/ (length L) 3)
(setq kq (append (list (list (nth i L) (nth (+ i 1) L) (nth (+ i 2) L))) kq))
(setq i (+ i 3))
)
kq
)
;;;-----------------------------------------------------
(defun C:IP ( / Le e0 e Lp p) ;;;Intersection Points
(setq Le (ss2ent (ssget '((0 . "LINE,POLYLINE,LWPOLYLINE,SPLINE")))))
(repeat (1- (length Le))
(setq Le (vl-remove (setq e0 (car Le)) Le))
(foreach e Le (setq Lp (append Lp (inters e0 e))))
)
(foreach p Lp (entmake (list (cons 0 "POINT") (cons 10 (list (car p) (cadr p) 0.0)))))
(princ)
)
;;;-----------------------------------------------------

Thảo luận gốc

Lisp được chia sẻ trong chủ đề [Đã xong] Lisp xuất-nhập toạ độ. Xem đúng bài viết #411129 để đọc hướng dẫn và trao đổi thêm.

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