Viết lisp xử lý số liệu từ .txt vào trong cad
Các bác chỉnh sửa giúp em theo cách này với
- mình chỉ cần nhập khoảng cách giữa H1-H2, H2-H3,....
- sau đó tự động phun các cột đó vào CAD ( bỏ qua bước nhập điểm đặt dòng text thứ 1, 2...)
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/index.php?showtopic=64582&pid=202432&st=20&#entry202432
(defun c:itext(/ blk *tH* lstDis lstDisX lstVal fn mLstPnt rl i j p mtext)(vl-load-com)
(setq blk (vla-get-block (vla-get-activelayout(vla-get-activedocument (vlax-get-acad-object)))))
(setq *tH* 1)
(cond
((setq fn (getfiled "Chon file so lieu" "" "txt" 8))
(defun mtext (str p blk h / obj)
(vla-put-AttachmentPoint (setq obj (vla-addmtext blk (vlax-3d-point p) h str)) 4)
(vla-put-rotation obj (* pi 0.5))
)
(defun mLstPnt (p lstDisX lstVal)
(mapcar '(lambda(y z)(mtext y z blk *tH*))
lstVal
(cons p (mapcar '(lambda(x)(setq p (cons (+ (car p) x) (cdr p)))) lstDisX))
)
)
(setq fn (open fn "r") j 0)
(or tmpDis (setq tmpDis 1))
(while (setq rl (read-line fn))
(setq i 1 )
(setq p (getpoint (strcat "\nDiem dat Text dong thu "(itoa (setq j (1+ j)))" :"))
lstVal (mapcar 'vl-princ-to-string (read (strcat "(" rl ")"))))
(while (< i (1+ (length lstVal)))
(initget "u")
(setq tmpDis (cond ((getdist (strcat "\nKhoang cach tu cot H" (itoa i) "-> H" (itoa (setq i (1+ i))) " <" (vl-princ-to-string tmpDis) ">:")))(tmpDis)))
(cond
((or (= tmpDis "u")(= tmpdis "U"))(setq i (- i 2)))
(T (setq lstDisX (cons tmpDis lstDisX)))
)
)
(mLstPnt p (reverse lstDisX) lstVal)
(setq lstDis '())
)
(close fn)
)
)
)
- mình chỉ cần nhập khoảng cách giữa H1-H2, H2-H3,....
- sau đó tự động phun các cột đó vào CAD ( bỏ qua bước nhập điểm đặt dòng text thứ 1, 2...)
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/index.php?showtopic=64582&pid=202432&st=20&#entry202432
(defun c:itext(/ blk *tH* lstDis lstDisX lstVal fn mLstPnt rl i j p mtext)(vl-load-com)
(setq blk (vla-get-block (vla-get-activelayout(vla-get-activedocument (vlax-get-acad-object)))))
(setq *tH* 1)
(cond
((setq fn (getfiled "Chon file so lieu" "" "txt" 8))
(defun mtext (str p blk h / obj)
(vla-put-AttachmentPoint (setq obj (vla-addmtext blk (vlax-3d-point p) h str)) 4)
(vla-put-rotation obj (* pi 0.5))
)
(defun mLstPnt (p lstDisX lstVal)
(mapcar '(lambda(y z)(mtext y z blk *tH*))
lstVal
(cons p (mapcar '(lambda(x)(setq p (cons (+ (car p) x) (cdr p)))) lstDisX))
)
)
(setq fn (open fn "r") j 0)
(or tmpDis (setq tmpDis 1))
(while (setq rl (read-line fn))
(setq i 1 )
(setq p (getpoint (strcat "\nDiem dat Text dong thu "(itoa (setq j (1+ j)))" :"))
lstVal (mapcar 'vl-princ-to-string (read (strcat "(" rl ")"))))
(while (< i (1+ (length lstVal)))
(initget "u")
(setq tmpDis (cond ((getdist (strcat "\nKhoang cach tu cot H" (itoa i) "-> H" (itoa (setq i (1+ i))) " <" (vl-princ-to-string tmpDis) ">:")))(tmpDis)))
(cond
((or (= tmpDis "u")(= tmpdis "U"))(setq i (- i 2)))
(T (setq lstDisX (cons tmpDis lstDisX)))
)
)
(mLstPnt p (reverse lstDisX) lstVal)
(setq lstDis '())
)
(close fn)
)
)
)
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 202454_itext.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 ITEXT để chạy lisp.
Mã nguồn 202454_itext.lsp (trích từ bài viết gốc)
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/index.php?showtopic=64582&pid=202432&st=20entry202432
(defun c:itext(/ blk *tH* lstDis lstDisX lstVal fn mLstPnt rl i j p mtext)(vl-load-com)
(setq blk (vla-get-block (vla-get-activelayout(vla-get-activedocument (vlax-get-acad-object)))))
(setq *tH* 1)
(cond
((setq fn (getfiled "Chon file so lieu" "" "txt" 8))
(defun mtext (str p blk h / obj)
(vla-put-AttachmentPoint (setq obj (vla-addmtext blk (vlax-3d-point p) h str)) 4)
(vla-put-rotation obj (* pi 0.5))
)
(defun mLstPnt (p lstDisX lstVal)
(mapcar '(lambda(y z)(mtext y z blk *tH*))
lstVal
(cons p (mapcar '(lambda(x)(setq p (cons (+ (car p) x) (cdr p)))) lstDisX))
)
)
(setq fn (open fn "r") j 0)
(or tmpDis (setq tmpDis 1))
(while (setq rl (read-line fn))
(setq i 1 )
(setq p (getpoint (strcat "\nDiem dat Text dong thu "(itoa (setq j (1+ j)))" :"))
lstVal (mapcar 'vl-princ-to-string (read (strcat "(" rl ")"))))
(while (< i (1+ (length lstVal)))
(initget "u")
(setq tmpDis (cond ((getdist (strcat "\nKhoang cach tu cot H" (itoa i) "-> H" (itoa (setq i (1+ i))) " <" (vl-princ-to-string tmpDis) ">:")))(tmpDis)))
(cond
((or (= tmpDis "u")(= tmpdis "U"))(setq i (- i 2)))
(T (setq lstDisX (cons tmpDis lstDisX)))
)
)
(mLstPnt p (reverse lstDisX) lstVal)
(setq lstDis '())
)
(close fn)
)
)
)Thảo luận gốc
Lisp được chia sẻ trong chủ đề [Yêu cầu] Viết lisp xử lý số liệu từ .txt vào trong cad. Xem đúng bài viết #202454 để đọc hướng dẫn và trao đổi thêm.