Jump to content

Lisp lệnh VTL1 trong chủ đề “Lisp rải taluy trên đường cong”

Đây là lisp tôi sưu tầm và chỉnh sửa lại chút ít, có thể rải taluy cho các loại line, pline, spline, arc, circle ...

(Mới dừng ở việc vẽ taluy cho 1 đường, phần vẽ mái taluy giữa 2 đường tôi chưa sửa xong)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;vtl;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun nsl ()
 (if (/= scale nil)
   (progn
     (setq thongbao (strcat "Ty le ban ve ?, <1/" (itoa scale) ">:"))
     (if (not (setq scaletmp (getint thongbao)))
(setq scaletmp scale)
     )
   )
   (progn
     (setq thongbao "Ty le ban ve ? <1/1000>:")
     (if (not (setq scaletmp (getint thongbao)))
(setq scaletmp 1000)
     )
   )
 )

 (setq scale scaletmp)

 (setq Defaultdist (* (* scale 2) 0.002))
 (if (setq tg (getreal	(strcat	"\nKhoang cach ky hieu ta luy <"
			(rtos Defaultdist 2 2)
			">:"
		)
       )
     )
   (setq Defaultdist tg)
 )

 (setq	chieutaluy1
 1
sodoan 0
 )
)

(defun nsl1 ()

 (setq
   ktdoantaluy1 2
   tg		 (getreal (strcat "\nChieu dai doan ngan<"
			  (rtos ktdoantaluy1 2 2)
			  ">:"
		  )
	 )
 )
 (if tg
   (setq ktdoantaluy1 tg)
 )
 (setq
   ktdoantaluy2 6
   tg		 (getreal (strcat "\nChieu dai doan dai<"
			  (rtos ktdoantaluy2 2 2)
			  ">:"
		  )
	 )
 )
 (if tg
   (setq ktdoantaluy2 tg)
 )
 (setq
   khoangcachtl 2
   tg		 (getreal (strcat "\nKhoang cach giua cac doan<"
			  (rtos khoangcachtl 2 2)
			  ">:"
		  )
	 )
 )
 (if tg
   (setq khoangcachtl tg)
 )
 (setq
   sodoanngan 3
   tg	       (getint (strcat "\nSo doan ngan trong 1 doan dai<"
		       (rtos sodoanngan 2 0)
		       ">:"
	       )
       )
 )
 (if tg
   (setq sodoanngan tg)
 )

)


(Defun PlMake (Plist)			;  Create polyline entities
 (entmake '((0 . "POLYLINE")))
 (setq	n  (length Plist)
ic 0
 )
 (while (< ic n)
   (entmake (list (cons 0 "VERTEX") (cons 10 (nth ic Plist))))
   (setq ic (1+ ic)
   )
 )
 (entmake '((0 . "SEQEND")))

)


;;;----------------------------------------------------------------
(defun ve1doantaluy (p1 p2 / pvt diemcu ktdoantaluy ketthuc)
 (setq pvt (+ (angle p1 p2) (* (/ pi 2) chieutaluy)))
 (setq ketthuc 1)
 (if (< sodoan sodoanngan)
   (progn
     (setq ktdoantaluy ktdoantaluy1)
     (setq sodoan (1+ sodoan))
   )
   (progn
     (setq ktdoantaluy ktdoantaluy2)
     (setq sodoan 0)
   )
 )
 (setq p2 (polar p1 pvt ktdoantaluy))
 (plmake (list p1 p2))
 (setq dem (1+ dem))
)

(Defun xddsd (com epl kc / e0 e p dsd)
 (setq e0 (entlast))
 (while e0
   (setq e e0)
   (setq e0 (entnext e0))
 )
 (command com epl kc)
 (setq e (entnext e))
 (while e
   (setq p (cdr (assoc 10 (entget e))))
   (if	p
     (setq dsd (cons p dsd))
   )
   (setq e (entnext e))
 )
 (command "_.Undo" 1)
 (setq dsd dsd)
)
				; ve ta luy cho 1 doi tuong
(Defun vetaluy (ep / le e ketthuc them dsd thutu)
 (setq dem 0)
 (setq e (entget (car ep)))
 (if (or (= (cdr (assoc 0 e)) "LWPOLYLINE")
  (= (cdr (assoc 0 e)) "POLYLINE")
  (= (cdr (assoc 0 e)) "SPLINE")
  (= (cdr (assoc 0 e)) "LINE")
  (= (cdr (assoc 0 e)) "ARC")
  (= (cdr (assoc 0 e)) "CIRCLE")
     )

   (setq ketthuc 1)
   (prompt "\nDoi tuong duoc chon khong hop le")
 )
 (if ketthuc
   (progn
     (setq thutu 0)
     (setq dsd (xddsd "_.Measure" ep khoangcachtl))
     (setq p1 (car dsd))
     (repeat (1- (length dsd))
(setq thutu (1+ thutu))
(setq p2 (nth thutu dsd))
(ve1doantaluy p1 p2)
(setq p1 p2)
     )
   )
 )
 (setq dem dem)
)

;;;==================================================
(Defun C:vtl1 (/ ep chon lai solan chon)

 (setvar "cmdecho" 0)
 (setvar "blipmode" 0)
 (command "undo" "g")
 (nsl)

 (setq ep 1)
 (while ep
   (setq solan	0
  chieutaluy 1
   )
   (setq ep (entsel "\nChon doi tuong ve ta luy..."))

   (if	ep
     (progn
(nsl1)
(setq solan (vetaluy ep))
(initget "Undo Change")
(while
  (setq chon (getkword "Undo/Change <enter for exit>: "))


   (if (= chon "Undo")
     (command "_.Undo" solan)
   )
   (if (= chon "Change")
     (progn
       (nsl1)

       (setq chieutaluy -1)
       (command "_.Undo" solan)
       (setq solan (vetaluy ep))

     )
   )

  (initget "Undo Change")
)

     )
   )
 )
 (command "undo" "e")
)

Lisp này khá tốt, chi cần sửa tay một tẹo là rải taluy cho 2 đường ngon ơ. Chỉ có điều nhập " khoảng cách ký hiệu taluy" để làm gì hả bác xìnâu? Và ấn Enter là tiếp tục chứ không phải thoát. Theo em để rải đẹp thì cần phải tách 2 layer taluy ngắn và taluy dài ra vì như vậy chiều dài taluy ngắn và taluy dài có thể thay đổi riêng biệt nhau làm cho đường taluy mềm mại hơn. Để em thử nâng cấp lên " chỉ rải trên một đoạn của đường cong mà mình tuỳ ý đặt" xem sao nhé (vì trên tuyến nó thay đổi đoạn đào, đắp liên tục)

Cách dùng

  1. Tải tệp 33961_vtl1.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 VTL1 để chạy lisp.

Mã nguồn 33961_vtl1.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/5947-lisp-r%E1%BA%A3i-taluy-tr%C3%AAn-%C4%91%C6%B0%E1%BB%9Dng-cong/?page=0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;vtl;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun nsl ()
 (if (/= scale nil)
   (progn
     (setq thongbao (strcat "Ty le ban ve ?, <1/" (itoa scale) ">:"))
     (if (not (setq scaletmp (getint thongbao)))
(setq scaletmp scale)
     )
   )
   (progn
     (setq thongbao "Ty le ban ve ? <1/1000>:")
     (if (not (setq scaletmp (getint thongbao)))
(setq scaletmp 1000)
     )
   )
 )

 (setq scale scaletmp)

 (setq Defaultdist (* (* scale 2) 0.002))
 (if (setq tg (getreal	(strcat	"\nKhoang cach ky hieu ta luy <"
			(rtos Defaultdist 2 2)
			">:"
		)
       )
     )
   (setq Defaultdist tg)
 )

 (setq	chieutaluy1
 1
sodoan 0
 )
)

(defun nsl1 ()

 (setq
   ktdoantaluy1 2
   tg		 (getreal (strcat "\nChieu dai doan ngan<"
			  (rtos ktdoantaluy1 2 2)
			  ">:"
		  )
	 )
 )
 (if tg
   (setq ktdoantaluy1 tg)
 )
 (setq
   ktdoantaluy2 6
   tg		 (getreal (strcat "\nChieu dai doan dai<"
			  (rtos ktdoantaluy2 2 2)
			  ">:"
		  )
	 )
 )
 (if tg
   (setq ktdoantaluy2 tg)
 )
 (setq
   khoangcachtl 2
   tg		 (getreal (strcat "\nKhoang cach giua cac doan<"
			  (rtos khoangcachtl 2 2)
			  ">:"
		  )
	 )
 )
 (if tg
   (setq khoangcachtl tg)
 )
 (setq
   sodoanngan 3
   tg	       (getint (strcat "\nSo doan ngan trong 1 doan dai<"
		       (rtos sodoanngan 2 0)
		       ">:"
	       )
       )
 )
 (if tg
   (setq sodoanngan tg)
 )

)


(Defun PlMake (Plist)			;  Create polyline entities
 (entmake '((0 . "POLYLINE")))
 (setq	n  (length Plist)
ic 0
 )
 (while (< ic n)
   (entmake (list (cons 0 "VERTEX") (cons 10 (nth ic Plist))))
   (setq ic (1+ ic)
   )
 )
 (entmake '((0 . "SEQEND")))

)


;;;----------------------------------------------------------------
(defun ve1doantaluy (p1 p2 / pvt diemcu ktdoantaluy ketthuc)
 (setq pvt (+ (angle p1 p2) (* (/ pi 2) chieutaluy)))
 (setq ketthuc 1)
 (if (< sodoan sodoanngan)
   (progn
     (setq ktdoantaluy ktdoantaluy1)
     (setq sodoan (1+ sodoan))
   )
   (progn
     (setq ktdoantaluy ktdoantaluy2)
     (setq sodoan 0)
   )
 )
 (setq p2 (polar p1 pvt ktdoantaluy))
 (plmake (list p1 p2))
 (setq dem (1+ dem))
)

(Defun xddsd (com epl kc / e0 e p dsd)
 (setq e0 (entlast))
 (while e0
   (setq e e0)
   (setq e0 (entnext e0))
 )
 (command com epl kc)
 (setq e (entnext e))
 (while e
   (setq p (cdr (assoc 10 (entget e))))
   (if	p
     (setq dsd (cons p dsd))
   )
   (setq e (entnext e))
 )
 (command "_.Undo" 1)
 (setq dsd dsd)
)
				; ve ta luy cho 1 doi tuong
(Defun vetaluy (ep / le e ketthuc them dsd thutu)
 (setq dem 0)
 (setq e (entget (car ep)))
 (if (or (= (cdr (assoc 0 e)) "LWPOLYLINE")
  (= (cdr (assoc 0 e)) "POLYLINE")
  (= (cdr (assoc 0 e)) "SPLINE")
  (= (cdr (assoc 0 e)) "LINE")
  (= (cdr (assoc 0 e)) "ARC")
  (= (cdr (assoc 0 e)) "CIRCLE")
     )

   (setq ketthuc 1)
   (prompt "\nDoi tuong duoc chon khong hop le")
 )
 (if ketthuc
   (progn
     (setq thutu 0)
     (setq dsd (xddsd "_.Measure" ep khoangcachtl))
     (setq p1 (car dsd))
     (repeat (1- (length dsd))
(setq thutu (1+ thutu))
(setq p2 (nth thutu dsd))
(ve1doantaluy p1 p2)
(setq p1 p2)
     )
   )
 )
 (setq dem dem)
)

;;;==================================================
(Defun C:vtl1 (/ ep chon lai solan chon)

 (setvar "cmdecho" 0)
 (setvar "blipmode" 0)
 (command "undo" "g")
 (nsl)

 (setq ep 1)
 (while ep
   (setq solan	0
  chieutaluy 1
   )
   (setq ep (entsel "\nChon doi tuong ve ta luy..."))

   (if	ep
     (progn
(nsl1)
(setq solan (vetaluy ep))
(initget "Undo Change")
(while
  (setq chon (getkword "Undo/Change <enter for exit>: "))


   (if (= chon "Undo")
     (command "_.Undo" solan)
   )
   (if (= chon "Change")
     (progn
       (nsl1)

       (setq chieutaluy -1)
       (command "_.Undo" solan)
       (setq solan (vetaluy ep))

     )
   )

  (initget "Undo Change")
)

     )
   )
 )
 (command "undo" "e")
)

Thảo luận gốc

Lisp được chia sẻ trong chủ đề Lisp rải taluy trên đường cong. Xem đúng bài viết #33961 để đọc hướng dẫn và trao đổi thêm.

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