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 : STTXYHChú ý : 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 (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))
Nhờ Anh Gia_bach có thể bổ sung lisp trên giúp em, khi bắn ra cad thì tạo ra các lớp :
1. Lớp point có kí hiệu điểm ( là điểm của tọa độ x, y trắc địa )
2. Lớp Số thứ tự
3. Lớp Cao độ
Mong được anh giúp, mong tin anh
- Tải lisp
- 96939_rft.lsp
Cách dùng
- Tải tệp 96939_rft.lsp về máy.
- 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ẽ.
- Gõ lệnh RFT để chạy lisp.
Mã nguồn 96939_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
(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 #96939 để đọc hướng dẫn và trao đổi thêm.