Jump to content

Lisp sắp xếp đối tượng theo đường cong

OK rồi bác. Thanks bác nhiều!!!
Thiếu 1 dòng (vl-load-com), em bổ sung luôn.

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/index.php?showtopic=64524
;Doan Van Ha - CADViet.com - Ngay 06/6/2012
;Muc dich: sap xep cac doi tuong doc theo curve.
(defun C:HA( / z ent pt pg ptc pdh cur d1 dh d2 p lst)
(vl-load-com)
(command "undo" "be") (setq osm (getvar "osmode"))
(setq z 1)
(while
(and
(setq ent (car (entsel (strcat "\nChon doi tuong thu " (itoa z) ": "))))
(setq pt (getpoint (strcat "\nChon diem goc cua doi tuong thu " (itoa z) ": "))))
(if (= z 1) (setq pg pt))
(setq lst (cons (list ent pt (distance pg pt)) lst))
(setq z (1+ z)))
(setq lst (reverse lst))
(setq ptc (getpoint "\nChon diem dat cua doi tuong thu 1 tren Curve: "))
(setq pdh (getpoint ptc "\nChon 1 diem tren Curve de xac dinh huong: "))
(setq cur (car (nentselp ptc)))
(setq d1 (vlax-curve-getDistAtPoint cur ptc))
(setq dh (vlax-curve-getDistAtPoint cur pdh))
(setvar "osmode" 0)
(foreach n lst
(if (> dh d1)
(setq d2 (+ d1 (caddr n)))
(setq d2 (- d1 (caddr n))))
(setq p (vlax-curve-getPointAtDist cur d2))
(command "move" (car n) "" (cadr n) p)
(command "rotate" (car n) "" p (/ (* 180 (angle '(0 0 0) (vlax-curve-getFirstDeriv cur (vlax-curve-getParamAtPoint cur p)))) pi)))
(command "undo" "end") (setvar "osmode" osm) (princ))

Cách dùng

  1. Tải tệp 202169_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 202169_ha.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/64524-y%C3%AAu-c%E1%BA%A7u-lisp-s%E1%BA%AFp-x%E1%BA%BFp-%C4%91%E1%BB%91i-t%C6%B0%E1%BB%A3ng-theo-%C4%91%C6%B0%E1%BB%9Dng-cong/
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/index.php?showtopic=64524
;Doan Van Ha - CADViet.com - Ngay 06/6/2012
;Muc dich: sap xep cac doi tuong doc theo curve.
(defun C:HA( / z ent pt pg ptc pdh cur d1 dh d2 p lst)
(vl-load-com)
(command "undo" "be") (setq osm (getvar "osmode"))
(setq z 1)
(while
 (and
  (setq ent (car (entsel (strcat "\nChon doi tuong thu " (itoa z) ": "))))
  (setq pt (getpoint (strcat "\nChon diem goc cua doi tuong thu " (itoa z) ": "))))
 (if (= z 1) (setq pg pt))
 (setq lst (cons (list ent pt (distance pg pt)) lst))
 (setq z (1+ z)))
(setq lst (reverse lst))
(setq ptc (getpoint "\nChon diem dat cua doi tuong thu 1 tren Curve: "))
(setq pdh (getpoint ptc "\nChon 1 diem tren Curve de xac dinh huong: "))
(setq cur (car (nentselp ptc)))
(setq d1 (vlax-curve-getDistAtPoint cur ptc))
(setq dh (vlax-curve-getDistAtPoint cur pdh))
(setvar "osmode" 0)
(foreach n lst
 (if (> dh d1)
  (setq d2 (+ d1 (caddr n)))
  (setq d2 (- d1 (caddr n))))
 (setq p (vlax-curve-getPointAtDist cur d2))
 (command "move" (car n) "" (cadr n) p)
 (command "rotate" (car n) "" p (/ (* 180 (angle '(0 0 0) (vlax-curve-getFirstDeriv cur (vlax-curve-getParamAtPoint cur p)))) pi)))
(command "undo" "end") (setvar "osmode" osm) (princ))

Thảo luận gốc

Lisp được chia sẻ trong chủ đề [Yêu cầu] Lisp sắp xếp đối tượng theo đường cong. Xem đúng bài viết #202169 để đọc hướng dẫn và trao đổi thêm.

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