Lisp xuất nhập thông tin tọa độ điểm
Vấn đề tui chưa làm được là vị trí con trỏ để ghi text tui open file với method "a" thì số liệu lại cứ ghi ra cuối file. hoặc báo lỗi. Các bác xem giúp tui xem sai cú pháp ở đâu?
(defun c:ntn ( / fn fid strht vt x y z) (defun pos (sub st / l1 l2 index) (setq index 1 l1 (strlen sub) l2 (strlen st) ) (while (and (<= (+ index l1 -1) l2) (/= sub (substr st index l1))) (setq index (1+ index)) ) (if (= sub (substr st index l1)) index nil ) ) (princ "vvvvvvvvvvvvvvvvvvvv") (setq fn (getfiled "Chon tep ntd can nhap TN" (getvar "dwgprefix") "txt" 1)) (setq fid (open fn "a")) (setq tencoc(getstring "\n nhap ten coc:")) (while (setq strht (read-line fid)) (setq strht (strcat strht "\t\t\t\t")) (if (/= strht " ") (progn (setq vt (pos "\t" strht) mot (substr strht 1 (1- vt)) strht (substr strht (1+ vt)) vt (pos "\t" strht) hai (substr strht 1 (1- vt)) strht (substr strht (1+ vt)) vt (pos "\t" strht) ba (substr strht 1 (1- vt)) strht (substr strht (1+ vt)) vt (pos "\t" strht) bon (substr strht 1 (1- vt)) strht (substr strht (1+ vt)) ) );het progn ); het if (princ "da lam den day") (if (and (= mot "POLE") (= tencoc hai)) (progn (princ "\nda lam den day nua") (write-line "da tim duoc coc" fid) ) ) ) (close fid) )
- Tải lisp
- 199584_ntn.lsp
Cách dùng
- Tải tệp 199584_ntn.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 NTN để chạy lisp.
Mã nguồn 199584_ntn.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/63912-y%C3%AAu-c%E1%BA%A7u-lisp-xu%E1%BA%A5t-nh%E1%BA%ADp-th%C3%B4ng-tin-t%E1%BB%8Da-%C4%91%E1%BB%99-%C4%91i%E1%BB%83m/?tab=comments
(defun c:ntn ( / fn fid strht vt x y z)[/font][/color]
[color=#282828][font=helvetica, arial, sans-serif] (defun pos (sub st / l1 l2 index)
(setq index 1
l1 (strlen sub)
l2 (strlen st)
)
(while
(and (<= (+ index l1 -1) l2) (/= sub (substr st index l1)))
(setq index (1+ index))
)
(if (= sub (substr st index l1))
index
nil
)
)[/font][/color]
[color=#282828][font=helvetica, arial, sans-serif]
(princ "vvvvvvvvvvvvvvvvvvvv")
(setq fn (getfiled "Chon tep ntd can nhap TN" (getvar "dwgprefix") "txt" 1))
(setq fid (open fn "a"))[/font][/color]
[color=#282828][font=helvetica, arial, sans-serif] (setq tencoc(getstring "\n nhap ten coc:"))
(while (setq strht (read-line fid))
(setq strht (strcat strht "\t\t\t\t"))
(if (/= strht " ")
(progn
(setq
vt (pos "\t" strht)
mot (substr strht 1 (1- vt))
strht (substr strht (1+ vt))
vt (pos "\t" strht)
hai (substr strht 1 (1- vt))
strht (substr strht (1+ vt))
vt (pos "\t" strht)
ba (substr strht 1 (1- vt))
strht (substr strht (1+ vt))[/font][/color]
[color=#282828][font=helvetica, arial, sans-serif] vt (pos "\t" strht)
bon (substr strht 1 (1- vt))
strht (substr strht (1+ vt))
)
);het progn
); het if
(princ "da lam den day")
(if (and (= mot "POLE") (= tencoc hai))
(progn
(princ "\nda lam den day nua")
(write-line "da tim duoc coc" fid)
)
)
)
(close fid)
)[/font][/color]
[color=#282828][font=helvetica, arial, sans-serif]Thảo luận gốc
Lisp được chia sẻ trong chủ đề [Yêu cầu] Lisp xuất nhập thông tin tọa độ điểm. Xem đúng bài viết #199584 để đọc hướng dẫn và trao đổi thêm.