Jump to content

Lisp lệnh ALP trong chủ đề “Nhờ viết lisp convert arc thành pline có 2 đầu là 2 đoạn thẳng”

@Duong Nhat Duy

 

2 giờ trước, Duong Nhat Duy đã nói:

Mình đang rất gấp, mình xin phép được nhờ các ae trong forum viết hoặc lên ý tưởng hộ mình vấn đề sau:

Mình có các arc rời rạc, cần 1 lisp chuyển (hoặc tạo) arc đó thành 1 pline, trong đó có 2 đầu là 2 đoạn thẳng, ở giữa là arc, độ dài 2 đoạn thẳng cho mình chỉ định (ví dụ 1,2,3 gì đấy, lấy bằng hàm getPointatDist gì gì đó, để ra 1 cái điểm cách 2 mút chính xác 1 khoảng như đã chỉ định, bán kính của arc mới chính bằng arc cũ.

Phiền các bạn giúp đỡ mình nhé, mình xin cảm ơn !

 

chữa cháy nhé, không biết có đúng ý hay không. CHú ý dòng lệnh command, mình chạy trên acad2007 không bị áo lỗi

Vòng lập và tham số chiều dài Bạn viết thêm vào nhé

 

(defun c:alp (/ ANGE ANGS APE APS E1 E2 EN EP L PE PS SP SS);arc + line => polyline
  (setq	en   (car (entsel "\nChon arc: "))
	ep   (vlax-curve-getEndPoint en)
	sp   (vlax-curve-getStartPoint en)
	l    (vlax-curve-getDistAtPoint en ep)
	ps   (vlax-curve-getPointAtDist en 1e-8)
	pe   (vlax-curve-getPointAtDist en (- l 1e-8))
	aps  (angle ps sp)
	ape  (angle pe ep)
	angs (angle '(0 0)
		    (Vlax-curve-getfirstderiv
		      en
		      (vlax-curve-getParamAtPoint en sp)
		    ) ;_ end of Vlax-curve-getfirstderiv
	     ) ;_ end of angle
	ange (angle '(0 0)
		    (Vlax-curve-getfirstderiv
		      en
		      (vlax-curve-getParamAtPoint en ep)
		    ) ;_ end of Vlax-curve-getfirstderiv
	     ) ;_ end of angle
  ) ;_ end of setq
  (if (< 1. (abs (- ape ange)))
    (setq ange (+ ange pi))
    ange
  ) ;_ end of if
  (if (< 1. (abs (- aps angs)))
    (setq angs (+ angs pi))
    angs
  ) ;_ end of if
  (setq	e1 (entmakex (list '(0 . "LINE")
			   (cons 10 sp)
			   (cons 11 (polar sp angs 5))
		     ) ;_ end of list
	   ) ;_ end of entmakex
  ) ;_ end of setq
  (setq	e2 (entmakex (list '(0 . "LINE")
			   (cons 10 ep)
			   (cons 11 (polar ep ange 5))
		     ) ;_ end of list
	   ) ;_ end of entmakex
  ) ;_ end of setq
  (setq ss (ssadd))
  (ssadd en ss)
  (ssadd e1 ss)
  (ssadd e2 ss)
  (command ".pedit" "m" ss "" "y" "j" 0 "")
  (princ)
)

 

Tệp .lsp gốc không còn trên máy chủ. Hãy chép mã nguồn bên dưới (lấy từ bài viết gốc) vào một tệp văn bản, lưu với đuôi .lsp.

Cách dùng

  1. Chép mã nguồn, lưu thành tệp 433968_alp.lsp.
  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 ALP để chạy lisp.

Mã nguồn 433968_alp.lsp (trích từ bài viết gốc)

(defun c:alp (/ ANGE ANGS APE APS E1 E2 EN EP L PE PS SP SS);arc + line => polyline
  (setq	en   (car (entsel "\nChon arc: "))
	ep   (vlax-curve-getEndPoint en)
	sp   (vlax-curve-getStartPoint en)
	l    (vlax-curve-getDistAtPoint en ep)
	ps   (vlax-curve-getPointAtDist en 1e-8)
	pe   (vlax-curve-getPointAtDist en (- l 1e-8))
	aps  (angle ps sp)
	ape  (angle pe ep)
	angs (angle '(0 0)
		    (Vlax-curve-getfirstderiv
		      en
		      (vlax-curve-getParamAtPoint en sp)
		    ) ;_ end of Vlax-curve-getfirstderiv
	     ) ;_ end of angle
	ange (angle '(0 0)
		    (Vlax-curve-getfirstderiv
		      en
		      (vlax-curve-getParamAtPoint en ep)
		    ) ;_ end of Vlax-curve-getfirstderiv
	     ) ;_ end of angle
  ) ;_ end of setq
  (if (< 1. (abs (- ape ange)))
    (setq ange (+ ange pi))
    ange
  ) ;_ end of if
  (if (< 1. (abs (- aps angs)))
    (setq angs (+ angs pi))
    angs
  ) ;_ end of if
  (setq	e1 (entmakex (list '(0 . "LINE")
			   (cons 10 sp)
			   (cons 11 (polar sp angs 5))
		     ) ;_ end of list
	   ) ;_ end of entmakex
  ) ;_ end of setq
  (setq	e2 (entmakex (list '(0 . "LINE")
			   (cons 10 ep)
			   (cons 11 (polar ep ange 5))
		     ) ;_ end of list
	   ) ;_ end of entmakex
  ) ;_ end of setq
  (setq ss (ssadd))
  (ssadd en ss)
  (ssadd e1 ss)
  (ssadd e2 ss)
  (command ".pedit" "m" ss "" "y" "j" 0 "")
  (princ)
)

Thảo luận gốc

Lisp được chia sẻ trong chủ đề Nhờ viết lisp convert arc thành pline có 2 đầu là 2 đoạn thẳng. Xem đúng bài viết #433968 để đọc hướng dẫn và trao đổi thêm.

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