Jump to content

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

 

Bạn chạy thử LISP đọc file txt có cấu trúc file dữ liệu như yêu cầu : STTXYH

Chú ý : trong file dữ liệu bạn Post lên, 3 dòng (57,189,213) có cấu trúc khác biệt.

Chiều cao Txt có thể thay đổi tại dòng : (setq h ....)

(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)))	      (vla-addtext spc val (vlax-3d-point pt) h) ))))  ))  (princ))

Lisp bị lỗi thế này : Command: ; error: malformed list on input

Ai giúp với

Cách dùng

  1. Tải tệp 285746_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 285746_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=5
(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)))	      (vla-addtext spc val (vlax-3d-point pt) h) ))))  ))  (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 #285746 để đọc hướng dẫn và trao đổi thêm.

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