Jump to content

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

To : khaosat2009

Rất tiếc, Tui e rằng không đủ thời gian để thực hiện các yêu cầu này.

Nhân đây nhờ các bạn khác giúp khaosat2009 giùm.

 

Bạn chạy thử :

(defun c:RFT(/ data f h line pt spc ten val);Read File Txt
(vl-load-com)
 (defun Split (Str Char / Lst pos)
   (while (setq pos (vl-string-search Char Str))
     (if (null Lst)
(setq Lst (list (substr Str 1 pos)))
(setq Lst (append Lst (list (read (substr Str 1 pos))))))
     (setq Str (substr Str (+ pos 2)) ))
   (setq Lst (append Lst (list (read Str)))))

 (if (setq ten (getfiled "Chon File txt" (getvar "dwgprefix") "txt" 8))
   (progn
     (setq spc (vla-get-ModelSpace (vla-get-ActiveDocument(vlax-get-Acad-Object))))
     (setq h (* (getvar "dimtxt")(getvar "dimscale")))
     (setq f (open (findfile ten) "r"))
     (while (setq Line (read-line f))
(if (vl-string-search "\t" Line)
  (progn
    (setq data (split Line "\t" )
	  val (car data)
	  pt  (cdr data) )
    (if (not(vl-catch-all-error-p (vl-catch-all-apply 'vlax-3d-point pt)))
      (progn
	(vla-addtext spc val (vlax-3d-point pt) h)
	(vla-addpoint spc (vlax-3d-point pt))) ))))  ))
 (princ))

Cám ơn Anh Gia_bach,

Rất mong được sự giúp đỡ chung của các anh chị.

Mong tin

Cách dùng

  1. Tải tệp 97186_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 97186_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/
(defun c:RFT(/ data f h line pt spc ten val);Read File Txt
(vl-load-com)
 (defun Split (Str Char / Lst pos)
   (while (setq pos (vl-string-search Char Str))
     (if (null Lst)
(setq Lst (list (substr Str 1 pos)))
(setq Lst (append Lst (list (read (substr Str 1 pos))))))
     (setq Str (substr Str (+ pos 2)) ))
   (setq Lst (append Lst (list (read Str)))))

 (if (setq ten (getfiled "Chon File txt" (getvar "dwgprefix") "txt" 8))
   (progn
     (setq spc (vla-get-ModelSpace (vla-get-ActiveDocument(vlax-get-Acad-Object))))
     (setq h (* (getvar "dimtxt")(getvar "dimscale")))
     (setq f (open (findfile ten) "r"))
     (while (setq Line (read-line f))
(if (vl-string-search "\t" Line)
  (progn
    (setq data (split Line "\t" )
	  val (car data)
	  pt  (cdr data) )
    (if (not(vl-catch-all-error-p (vl-catch-all-apply 'vlax-3d-point pt)))
      (progn
	(vla-addtext spc val (vlax-3d-point pt) h)
	(vla-addpoint spc (vlax-3d-point pt))) ))))  ))
 (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 #97186 để đọc hướng dẫn và trao đổi thêm.

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