Lisp lệnh GHEPFILE trong chủ đề “Nhờ hướng dẫn sử lý file số liệu(Text) bằng LISP”
Bác xem thử có được không nhé.
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
- Chép mã nguồn, lưu thành tệp 104648_ghepfile.lsp.
- 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 GHEPFILE để chạy lisp.
Mã nguồn 104648_ghepfile.lsp (trích từ bài viết gốc)
(defun Split(StrOrg Delimiter / ListAnswer)
(setq ListAnswer nil)
(while (not (null (setq DeliPoint (vl-string-search Delimiter StrOrg))))
(setq ListAnswer (append ListAnswer (list (substr StrOrg 1 DeliPoint))))
(setq StrOrg (substr StrOrg (+ (strlen Delimiter) 1 DeliPoint)))
)
(setq ListAnswer (append ListAnswer (list StrOrg)))
)
(defun StringX(Char Num)
(setq I 0
String "")
(while (< I Num)
(setq I (1+ I)
String (strcat String Char))
)
)
(defun c:ghepfile()
(setq File1 (open "D:\\FILETEXT\\FILE1.txt" "r")
File3 (open "D:\\FILETEXT\\FILE3.txt" "a"))
(while (setq Line1 (read-line File1))
(setq LLine1 (split Line1 " ")
I 0
J 0
Len (length LLine1))
(while (< i Len)
(if (/= (nth I LLine1) "")
(setq Str1 (nth I LLine1)
J I
I Len)
)
(setq I (1+ I))
)
(setq File2 (open "D:\\FILETEXT\\FILE2.txt" "r")
W 0)
(while (setq Line2 (read-line File2))
(setq LLine2 (split Line2 " ")
Str2 (nth 0 LLine2)
LLine21 (split (nth 1 LLine2) ",")
I 0
Len (length LLine21))
(while (< I Len)
(if (= Str1 (nth I LLine21))
(progn
(setq I Len
W 1)
(write-line (strcat (stringx " " J) Str2 (substr Line1 (+ J 1))) File3)
)
)
(Setq I (1+ I))
)
)
(close file2)
(if (= W 0) (write-line Line1 File3))
)
(close file1)
(close file3)
)Thảo luận gốc
Lisp được chia sẻ trong chủ đề Nhờ hướng dẫn sử lý file số liệu(Text) bằng LISP. Xem đúng bài viết #104648 để đọc hướng dẫn và trao đổi thêm.