Jump to content

Lisp lệnh VESPL trong chủ đề “Autolisp 3D”


Ðây là file dữ liệu mẫu dạng TEXT, cứ mỗi dòng trống là kết thúc một spline : https://www.cadviet.com/upfiles/spline.txt
Còn ðây là code, bạn tham khảo xem ðýợc không. Mình không có nhiều thời gian nên có lẽ cũng không tốt lắm

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 55145_vespl.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 VESPL để chạy lisp.

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

;ve spline
(defun C:VESPL( / n1 f1 st lis p shd kt)
;;;;
(defun ptdanhsach(st ch / st1 i lis ch1)
 (setq st1 "")
 (setq i 1 lis nil)
 (while (<= i (strlen st))
(setq ch1 (substr st i 1))
(if  (= ch ch1) (progn
  (setq lis (append lis (list st1)))
  (setq st1 "")
)  (progn
  (setq st1 (strcat st1 ch1))
  (if (= i (strlen st)) (setq lis (append lis (list st1))))
  )
)
(setq i (1+ i))
 )
 lis
)
(defun opw( tieude duoi)
 (setq duongdanfile (getfiled tieude duongdanfile duoi 7))
) 
(defun opr( tieude duoi)
 (setq duongdanfile (getfiled tieude duongdanfile duoi 6))
) 
;;ham chinh
 (setq n1 (opr "Ten file toa do : " "txt"))
 (setq f1 (open n1 "r") kt nil)
 (while (setq st (read-line f1))
(if (/= st "") (progn
  (setq lis (ptdanhsach st "\t") p nil)
  (cond
	((= (length lis) 4)
	  (setq shd (nth 0 lis) p (list (atof (nth 1 lis)) (atof (nth 2 lis)) (atof (nth 3 lis))))
	)
	((= (length lis) 3)
	  (setq p (list (atof (nth 1 lis)) (atof (nth 2 lis)) (atof (nth 3 lis))))
	)
	(T (setq p nil))
  )
  (if p (progn
	(if (null kt) (progn
	  (setq kt T)
	  (command "_.spline" p)
	) (command p))
  ))
) (progn
  (command "" "" "")
  (setq kt nil p nil)
))
 )
 (if (and kt p) (command "" "" ""))
 (close f1)
 (princ)
)

Thảo luận gốc

Lisp được chia sẻ trong chủ đề Autolisp 3D. Xem đúng bài viết #55145 để đọc hướng dẫn và trao đổi thêm.

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