Jump to content

lisp Phun tọa độ các điểm từ file txt vào CAD


to : thanhduan2407
- Bạn tham khảo cách sử dụng hàm Split ở trên, chỉ đơn giản thay dòng (split Line "\t") bằng (split Line)
và dòng (vl-string-search "\t" Line) bằng (wcmatch Line (strcat "*"(chr 9)"*,*"(chr 32)"*,*`"(chr 44)"*"))
- Nếu bạn đã biết VB thì việc học LISP rất đơn giản (Ngôn ngữ chỉ là cách thể hiện, thuật toán mới là vấn đề)
- Bạn có thể tham khảo bài Hướng dẫn lập trình Lisp, Hãy tự mình khám phá... của bác SSG.

Cách dùng

  1. Tải tệp 102365_rft.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 RFT để chạy lisp.

Mã nguồn 102365_rft.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/20044-y%C3%AAu-c%E1%BA%A7u-lisp-phun-t%E1%BB%8Da-%C4%91%E1%BB%99-c%C3%A1c-%C4%91i%E1%BB%83m-t%E1%BB%AB-file-txt-v%C3%A0o-cad/?page=2&tab=comments#comment-101694
(defun c:RFT(/ code data f h line pt pxy spc txt stt ten);Read File Txt
 ;|  By : Gia Bach, gia_bach @  www.CadViet.com             |;    
 (vl-load-com)
(defun Split(str / i kitu line lst txtPhanbiet)
 (setq i 1 txtPhanbiet (strcat(chr 9)(chr 32)(chr 44)))
 (while (< i (strlen str))
   (setq kitu (substr str i 1))
   (if (vl-string-search kitu  txtPhanbiet)
     (progn
(if (null Lst)
  (setq Lst (list (substr Str 1 (- i 1))))
  (setq Lst (append Lst (list (read (substr Str 1 (- i 1)))))))
(setq Str (substr Str (+ i 1)) i 1))
     (setq i (1+ i)) )   )
 (setq Lst (append Lst (list Str)))  )
 (or *h* (setq *h* 2 ))
 (initget 6)
 (setq h (getdist (strcat "\nNhap chieu cao Text <" (rtos *h*) "> :")) )
 (if h (setq *h* h) (setq h *h*))
 (if (setq ten (getfiled "Chon File txt" (getvar "dwgprefix") "txt" 8))
   (progn
     (or (tblsearch "layer" "Point") (command "-layer" "n" "Point" "") )
     (or (tblsearch "layer" "Sothutu") (command "-layer" "n" "Sothutu" "c" 3 "Sothutu" "") )
     (or (tblsearch "layer" "Caodo") (command "-layer" "n" "Caodo" "c" 4 "Caodo" "") )
     (or (tblsearch "layer" "Code") (command "-layer" "n" "Code" "c" 2 "Code" "") )
     (setq spc (vla-get-ModelSpace (vla-get-ActiveDocument(vlax-get-Acad-Object))))
     (setq f (open (findfile ten) "r"))
     (while (setq Line (read-line f))
(if (wcmatch Line (strcat "*"(chr 9)"*,*"(chr 32)"*,*`"(chr 44)"*"))
  (progn
    (setq data (split Line) code (last data))
    (if (and
	  (= (vl-list-length data)5)
	  (setq pt (vl-remove code (cdr data)))
	  (not(vl-catch-all-error-p (vl-catch-all-apply 'vlax-3d-point pt))) )
      (progn
	(setq stt (car data) pXY (list (car pt)(cadr pt)))
	(vla-put-Layer (vla-addpoint spc (vlax-3d-point pXY)) "Point")
	(vla-put-Layer (setq txt (vla-addtext spc stt (vlax-3d-point (list 0 0 0)) h)) "Sothutu")
	(vla-put-Alignment txt 8)
	(vla-put-TextAlignmentPoint txt (vlax-3d-point pXY))
	(vla-put-Layer (setq txt (vla-addtext spc code (vlax-3d-point (list 0 0 0)) h)) "Code")
	(vla-put-Alignment txt 6)
	(vla-put-TextAlignmentPoint txt (vlax-3d-point (polar pXY 0 (* 0.2 h))))
	(vla-put-Layer (vla-addtext spc (caddr pt) (vlax-3d-point pXY) h) "Caodo")	))))) ) )
 (princ))

Thảo luận gốc

Lisp được chia sẻ trong chủ đề [Yêu cầu] lisp Phun tọa độ các điểm từ file txt vào CAD. Xem đúng bài viết #102365 để đọc hướng dẫn và trao đổi thêm.

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