Jump to content

Lisp lệnh PL-CENTER trong chủ đề “Cách vẽ 1 đoạn thẳng cách đều 2 đoạn thẳng cho trước.”

Lisp tạo đường PLine giữa 2 đường Pline khác: 

 



; Write by Danh Cong - Cadviet.com 13-11-2020
; SDT 0336 760 750

(defun c:PL-CENTER (/ I KC LEN_PL_1 LST_POINT N PL_1 PL_2 PT1 PT2 PT3)
  (vl-load-com)
  (prompt "Select PLINE_1 ?")
  (setq PL_1 (car (entsel)))
  (prompt "Select PLINE_2 ?")
  (setq PL_2 (car (entsel)))

  (INITGET (+ 1 2 4))
  (setq KC (getreal "/nKhoang cach chia ?"))

  (setq lst_Point '())

  (setq Len_PL_1 (vlax-curve-getDistAtParam PL_1 (vlax-curve-getEndParam PL_1)))
  (setq i 0 n (/ Len_PL_1 KC))

  (while (< i n)
    (progn
      (setq Pt1 (vlax-curve-getPointAtDist PL_1 (* i KC)))
      (setq Pt2 (vlax-curve-getClosestPointTo PL_2 Pt1))
      (setq Pt3 (list (/ (+ (nth 0 Pt1) (nth 0 Pt2)) 2) (/ (+ (nth 1 Pt1) (nth 1 Pt2)) 2)))
      (setq lst_Point (append lst_Point (list Pt3)))
      (setq i (+ i 1))
      ); endprogn
    ); end while

  (acet-pline-make (list lst_Point))
  
  (princ))

Cách dùng

  1. Tải tệp 451502_pl-center.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 PL-CENTER để chạy lisp.

Mã nguồn 451502_pl-center.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/183716-c%C3%A1ch-v%E1%BA%BD-1-%C4%91o%E1%BA%A1n-th%E1%BA%B3ng-c%C3%A1ch-%C4%91%E1%BB%81u-2-%C4%91o%E1%BA%A1n-th%E1%BA%B3ng-cho-tr%C6%B0%E1%BB%9Bc/



	; Write by Danh Cong - Cadviet.com 13-11-2020
	; SDT 0336 760 750



	(defun c:PL-CENTER (/ I KC LEN_PL_1 LST_POINT N PL_1 PL_2 PT1 PT2 PT3)
	  (vl-load-com)
	  (prompt "Select PLINE_1 ?")
	  (setq PL_1 (car (entsel)))
	  (prompt "Select PLINE_2 ?")
	  (setq PL_2 (car (entsel)))



	  (INITGET (+ 1 2 4))
	  (setq KC (getreal "/nKhoang cach chia ?"))



	  (setq lst_Point '())



	  (setq Len_PL_1 (vlax-curve-getDistAtParam PL_1 (vlax-curve-getEndParam PL_1)))
	  (setq i 0 n (/ Len_PL_1 KC))



	  (while (< i n)
	    (progn
	      (setq Pt1 (vlax-curve-getPointAtDist PL_1 (* i KC)))
	      (setq Pt2 (vlax-curve-getClosestPointTo PL_2 Pt1))
	      (setq Pt3 (list (/ (+ (nth 0 Pt1) (nth 0 Pt2)) 2) (/ (+ (nth 1 Pt1) (nth 1 Pt2)) 2)))
	      (setq lst_Point (append lst_Point (list Pt3)))
	      (setq i (+ i 1))
	      ); endprogn
	    ); end while



	  (acet-pline-make (list lst_Point))
	  
	  (princ))

Thảo luận gốc

Lisp được chia sẻ trong chủ đề Cách vẽ 1 đoạn thẳng cách đều 2 đoạn thẳng cho trước.. Xem đúng bài viết #451502 để đọc hướng dẫn và trao đổi thêm.

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