Jump to content

Lisp chỉ đúng khi sử dụng lần đâu

Vào lúc 12/2/2020 tại 05:55, 790312 đã nói:

Cảm ơn bác đã bỏ thời gian check. Nhưng bác sử dụng lisp này vẽ mũi tên xong, sau đó bác zoom nhỏ hình lại và vẽ đoạn thẳng khác dài hơn thì nó sẽ bị lỗi là chỉ vẽ mũi tên ở một đầu thôi bác ah. E gửi bác lisp e down ở bài 12 từ trên xuống của chính chủ, bác check như e nói xem. Cảm ơn bác nhiều.

  • sline.lsp
    lisp help
  •  

;; free lisp from cadviet.com
;; this lisp was downloaded from https://www.cadviet.com/forum/topic/47541-%C4%91%C3%A3-xong-lisp-v%E1%BA%BD-pline-m%C5%A9i-t%C3%AAn-2-%C4%91%E1%BA%A7u/
(defun c:sline (/ loop p1 p2 lstPnt)   
 (grtext -1 "Free from Cadviet.com @Ketxu")
 (setq lstPnt '())
 (if (not asize) (setq asize 1))      
 (if (not PThk)  (setq PThk 0.01))                 
 (defun GETR (val msg / tm)
   (setq tm (getreal (strcat msg " <" (rtos val 2 4) ">: ")))
   (cond ((= (type tm) 'REAL) (eval tm))
         ((= tm nil) (eval val))
         (t (princ "\007 *error* Nh\U+1EADp sai lo\U+1EA1i d\U+1EEF li\U+1EC7u") (eval val)) ) )
 (defun loop ()
   (cond ((and(setq p2 (getpoint p1 "\n\U+0110i\U+1EC3m ti\U+1EBFp theo : "))(setq lstPnt (append (list p2) lstPnt))) (command p2) 
                                    (setq p0 p1) (setq p1 p2) (loop))
         ( t (command "u" (polar p1 (angle p1 p0) asize)
                      "w" (/ asize 3) 0.0 p1 ""))))
 (setq asize (getr asize "\nK\U+00EDch th\U+01B0\U+1EDBc m\U+0169i t\U+00EAn :"))
 (setq PThk  (getr PThk "\n B\U+1EC1 r\U+1ED9ng PLine :"))
 (setq p1 (getpoint "\n\U+0110i\U+1EC3m b\U+1EAFt \U+0111\U+1EA7u : "))
 (setq lstPnt (append (list p1) lstPnt))
 (command "pline" p1 "w" 0.0 0.0)
 (setq p2 (getpoint p1 "\n\U+0110i\U+1EC3m ti\U+1EBFp theo : "))
 (setq lstPnt (append (list p2) lstPnt))
 (command "w" 0.0 (/ asize 3) (polar p1 (angle p1 p2) asize) 
          "w" PThk PThk p2)
 (setq p1 p2)
 (loop)
(if  (ST:Geo-ListLinear lstPnt)
(foreach pt (cdr (vl-remove (last lstPnt) lstPnt)) (ST:Entmake-Circle pt 50))
)
 (eval "Done")
)
(defun ST:Geo-Linear ( p1 p2 p3 fuzz)
 (
   (lambda ( a b c )
     (or
       (equal (+ a B) c fuzz)
       (equal (+ b c) a fuzz)
       (equal (+ c a) b fuzz)
     )
   )
   (distance p1 p2) (distance p2 p3) (distance p1 p3)
 )
)
(defun ST:Geo-ListLinear (lst / tmp)
(setq i 2)
(cond ((and (= (length lst) 3)(ST:Geo-Linear(car lst)(cadr lst)(caddr lst) 1e-8))(setq tmp T))
	(T (while (and (< i (1- (length lst)))
			(setq tmp (ST:Geo-Linear (nth 0 lst)(nth 1 lst) (nth (setq i (1+ i)) lst) 1e-8)))
			tmp
		)
	)
)
tmp
)
(defun ST:Entmake-Circle ( Pt Rad )(entmakex (list '(0 . "CIRCLE") (cons 10 pt)(cons 40 Rad))))

Đúng là có lúc lisp lỗi thật, đúng như bác NTDNV nói trên. Lỗi thì do anh KetXu chưa xử lý chế độ bắt điểm khi viết lisp thôi.

Tôi sửa thêm 1 số chỗ về bắt điểm nữa, bạn có thể tải về kiểm tra:



;; free lisp from cadviet.com
;; this lisp was downloaded from https://www.cadviet.com/forum/topic/47541-đã-xong-lisp-vẽ-pline-mũi-tên-2-đầu/
(defun c:sline (/ loop p1 p2 lstPnt)   
 (grtext -1 "Free from Cadviet.com @Ketxu")
 (setq lstPnt '())
 (if (not asize) (setq asize 1))      
 (if (not PThk)  (setq PThk 0.01))                 
 (defun GETR (val msg / tm)
   (setq tm (getreal (strcat msg " <" (rtos val 2 4) ">: ")))
   (cond ((= (type tm) 'REAL) (eval tm))
         ((= tm nil) (eval val))
         (t (princ "\007 *error* Nh\U+1EADp sai lo\U+1EA1i d\U+1EEF li\U+1EC7u") (eval val)) ) )
 (defun loop ()
   (cond ((and(setq p2 (getpoint p1 "\n\U+0110i\U+1EC3m ti\U+1EBFp theo : "))(setq lstPnt (append (list p2) lstPnt))) (command "non" p2) 
                                    (setq p0 p1) (setq p1 p2) (loop))
         ( t (command "u" (polar p1 (angle p1 p0) asize)
                      "w" (/ asize 3) 0.0 "non" p1 ""))))
 (setq asize (getr asize "\nK\U+00EDch th\U+01B0\U+1EDBc m\U+0169i t\U+00EAn :"))
 (setq PThk  (getr PThk "\n B\U+1EC1 r\U+1ED9ng PLine :"))
 (setq p1 (getpoint "\n\U+0110i\U+1EC3m b\U+1EAFt \U+0111\U+1EA7u : "))
 (setq lstPnt (append (list p1) lstPnt))
 (command "pline" "non" p1 "w" 0.0 0.0)
 (setq p2 (getpoint p1 "\n\U+0110i\U+1EC3m ti\U+1EBFp theo : "))
 (setq lstPnt (append (list p2) lstPnt))
 (command "w" 0.0 (/ asize 3) (polar p1 (angle p1 p2) asize) 
          "w" PThk PThk "non" p2)
 (setq p1 p2)
 (loop)
(if  (ST:Geo-ListLinear lstPnt)
(foreach pt (cdr (vl-remove (last lstPnt) lstPnt)) (ST:Entmake-Circle pt 50))
)
 (eval "Done")
)
(defun ST:Geo-Linear ( p1 p2 p3 fuzz)
 (
   (lambda ( a b c )
     (or
       (equal (+ a B) c fuzz)
       (equal (+ b c) a fuzz)
       (equal (+ c a) b fuzz)
     )
   )
   (distance p1 p2) (distance p2 p3) (distance p1 p3)
 )
)
(defun ST:Geo-ListLinear (lst / tmp)
(setq i 2)
(cond ((and (= (length lst) 3)(ST:Geo-Linear(car lst)(cadr lst)(caddr lst) 1e-8))(setq tmp T))
    (T (while (and (< i (1- (length lst)))
            (setq tmp (ST:Geo-Linear (nth 0 lst)(nth 1 lst) (nth (setq i (1+ i)) lst) 1e-8)))
            tmp
        )
    )
)
tmp
)
(defun ST:Entmake-Circle ( Pt Rad )(entmakex (list '(0 . "CIRCLE") (cons 10 pt)(cons 40 Rad))))v

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 444182_sline.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 SLINE để chạy lisp.

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

;; free lisp from cadviet.com
;; this lisp was downloaded from https://www.cadviet.com/forum/topic/47541-%C4%91%C3%A3-xong-lisp-v%E1%BA%BD-pline-m%C5%A9i-t%C3%AAn-2-%C4%91%E1%BA%A7u/
(defun c:sline (/ loop p1 p2 lstPnt)   
 (grtext -1 "Free from Cadviet.com @Ketxu")
 (setq lstPnt '())
 (if (not asize) (setq asize 1))      
 (if (not PThk)  (setq PThk 0.01))                 
 (defun GETR (val msg / tm)
   (setq tm (getreal (strcat msg " <" (rtos val 2 4) ">: ")))
   (cond ((= (type tm) 'REAL) (eval tm))
         ((= tm nil) (eval val))
         (t (princ "\007 *error* Nh\U+1EADp sai lo\U+1EA1i d\U+1EEF li\U+1EC7u") (eval val)) ) )
 (defun loop ()
   (cond ((and(setq p2 (getpoint p1 "\n\U+0110i\U+1EC3m ti\U+1EBFp theo : "))(setq lstPnt (append (list p2) lstPnt))) (command p2) 
                                    (setq p0 p1) (setq p1 p2) (loop))
         ( t (command "u" (polar p1 (angle p1 p0) asize)
                      "w" (/ asize 3) 0.0 p1 ""))))
 (setq asize (getr asize "\nK\U+00EDch th\U+01B0\U+1EDBc m\U+0169i t\U+00EAn :"))
 (setq PThk  (getr PThk "\n B\U+1EC1 r\U+1ED9ng PLine :"))
 (setq p1 (getpoint "\n\U+0110i\U+1EC3m b\U+1EAFt \U+0111\U+1EA7u : "))
 (setq lstPnt (append (list p1) lstPnt))
 (command "pline" p1 "w" 0.0 0.0)
 (setq p2 (getpoint p1 "\n\U+0110i\U+1EC3m ti\U+1EBFp theo : "))
 (setq lstPnt (append (list p2) lstPnt))
 (command "w" 0.0 (/ asize 3) (polar p1 (angle p1 p2) asize) 
          "w" PThk PThk p2)
 (setq p1 p2)
 (loop)
(if  (ST:Geo-ListLinear lstPnt)
(foreach pt (cdr (vl-remove (last lstPnt) lstPnt)) (ST:Entmake-Circle pt 50))
)
 (eval "Done")
)
(defun ST:Geo-Linear ( p1 p2 p3 fuzz)
 (
   (lambda ( a b c )
     (or
       (equal (+ a B) c fuzz)
       (equal (+ b c) a fuzz)
       (equal (+ c a) b fuzz)
     )
   )
   (distance p1 p2) (distance p2 p3) (distance p1 p3)
 )
)
(defun ST:Geo-ListLinear (lst / tmp)
(setq i 2)
(cond ((and (= (length lst) 3)(ST:Geo-Linear(car lst)(cadr lst)(caddr lst) 1e-8))(setq tmp T))
	(T (while (and (< i (1- (length lst)))
			(setq tmp (ST:Geo-Linear (nth 0 lst)(nth 1 lst) (nth (setq i (1+ i)) lst) 1e-8)))
			tmp
		)
	)
)
tmp
)
(defun ST:Entmake-Circle ( Pt Rad )(entmakex (list '(0 . "CIRCLE") (cons 10 pt)(cons 40 Rad))))

;; free lisp from cadviet.com

	;; this lisp was downloaded from https://www.cadviet.com/forum/topic/47541-đã-xong-lisp-vẽ-pline-mũi-tên-2-đầu/

	(defun c:sline (/ loop p1 p2 lstPnt)   

	 (grtext -1 "Free from Cadviet.com @Ketxu")

	 (setq lstPnt '())

	 (if (not asize) (setq asize 1))      

	 (if (not PThk)  (setq PThk 0.01))                 

	 (defun GETR (val msg / tm)

	   (setq tm (getreal (strcat msg " <" (rtos val 2 4) ">: ")))

	   (cond ((= (type tm) 'REAL) (eval tm))

	         ((= tm nil) (eval val))

	         (t (princ "\007 *error* Nh\U+1EADp sai lo\U+1EA1i d\U+1EEF li\U+1EC7u") (eval val)) ) )

	 (defun loop ()

	   (cond ((and(setq p2 (getpoint p1 "\n\U+0110i\U+1EC3m ti\U+1EBFp theo : "))(setq lstPnt (append (list p2) lstPnt))) (command "non" p2) 

	                                    (setq p0 p1) (setq p1 p2) (loop))

	         ( t (command "u" (polar p1 (angle p1 p0) asize)

	                      "w" (/ asize 3) 0.0 "non" p1 ""))))

	 (setq asize (getr asize "\nK\U+00EDch th\U+01B0\U+1EDBc m\U+0169i t\U+00EAn :"))

	 (setq PThk  (getr PThk "\n B\U+1EC1 r\U+1ED9ng PLine :"))

	 (setq p1 (getpoint "\n\U+0110i\U+1EC3m b\U+1EAFt \U+0111\U+1EA7u : "))

	 (setq lstPnt (append (list p1) lstPnt))

	 (command "pline" "non" p1 "w" 0.0 0.0)

	 (setq p2 (getpoint p1 "\n\U+0110i\U+1EC3m ti\U+1EBFp theo : "))

	 (setq lstPnt (append (list p2) lstPnt))

	 (command "w" 0.0 (/ asize 3) (polar p1 (angle p1 p2) asize) 

	          "w" PThk PThk "non" p2)

	 (setq p1 p2)

	 (loop)

	(if  (ST:Geo-ListLinear lstPnt)

	(foreach pt (cdr (vl-remove (last lstPnt) lstPnt)) (ST:Entmake-Circle pt 50))

	)

	 (eval "Done")

	)

	(defun ST:Geo-Linear ( p1 p2 p3 fuzz)

	 (

	   (lambda ( a b c )

	     (or

	       (equal (+ a B) c fuzz)

	       (equal (+ b c) a fuzz)

	       (equal (+ c a) b fuzz)

	     )

	   )

	   (distance p1 p2) (distance p2 p3) (distance p1 p3)

	 )

	)

	(defun ST:Geo-ListLinear (lst / tmp)

	(setq i 2)

	(cond ((and (= (length lst) 3)(ST:Geo-Linear(car lst)(cadr lst)(caddr lst) 1e-8))(setq tmp T))

	    (T (while (and (< i (1- (length lst)))

	            (setq tmp (ST:Geo-Linear (nth 0 lst)(nth 1 lst) (nth (setq i (1+ i)) lst) 1e-8)))

	            tmp

	        )

	    )

	)

	tmp

	)

	(defun ST:Entmake-Circle ( Pt Rad )(entmakex (list '(0 . "CIRCLE") (cons 10 pt)(cons 40 Rad))))v

Thảo luận gốc

Lisp được chia sẻ trong chủ đề [Yêu cầu] Lisp chỉ đúng khi sử dụng lần đâu. Xem đúng bài viết #444182 để đọc hướng dẫn và trao đổi thêm.

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