Jump to content

Lisp lệnh IPT trong chủ đề “Import text từ text file vào autocad”

Vì không gửi file cad nên tôi chỉ viết phần xuất text, phần kẻ khung bạn tự làm.

Tên lệnh và các thông số chiều cao text, kc hàng. .. bạn tự sửa trong lisp cho phù hợp.

(defun eText (p h s u v) (entmake (list '(0 . "TEXT") (cons 10 p)(cons 11 p) (cons 1 s)
                                                                 (cons 40 h)(cons 72 u)(cons 73 v))))
(defun C:IPT( / file h i line n p r s x y)
    (setq s (getfiled "\nFile text:" "" "txt" 0))
    (setq h 3 ; cao text
                r 5 ; kc hang
                n '(3 2 5 6)
                x '(20 40 60 80 )) ; vi tri
    (setq file (open s "r") p (getpoint "\nVi tri: ") y (cadr p))
    (while (setq s (read-line file))
        (setq line (read (strcat "(" s ")")))
        (if (>= (length line) 7)
            (progn
                (setq i 0 y (- y r))
                (repeat 4
                    (eText (list (+ (car p) (nth i x)) y) h (itoa(nth (nth i n) line)) 2 1)
                    (setq i (1+ i))
    ) ) ) )
    (close file)
)

Uống cafe thì mất time di chuyển, thay vào đó, nếu thấy lisp có giá trị, bạn nhắn tin từ thiện rồi chụp ảnh post lên

http://1400.vn/tin-tuc

Cách dùng

  1. Tải tệp 432797_ipt.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 IPT để chạy lisp.

Mã nguồn 432797_ipt.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/174999-import-text-t%E1%BB%AB-text-file-v%C3%A0o-autocad/
(defun eText (p h s u v) (entmake (list '(0 . "TEXT") (cons 10 p)(cons 11 p) (cons 1 s)
                                                                 (cons 40 h)(cons 72 u)(cons 73 v))))
(defun C:IPT( / file h i line n p r s x y)
    (setq s (getfiled "\nFile text:" "" "txt" 0))
    (setq h 3 ; cao text
                r 5 ; kc hang
                n '(3 2 5 6)
                x '(20 40 60 80 )) ; vi tri
    (setq file (open s "r") p (getpoint "\nVi tri: ") y (cadr p))
    (while (setq s (read-line file))
        (setq line (read (strcat "(" s ")")))
        (if (>= (length line) 7)
            (progn
                (setq i 0 y (- y r))
                (repeat 4
                    (eText (list (+ (car p) (nth i x)) y) h (itoa(nth (nth i n) line)) 2 1)
                    (setq i (1+ i))
    ) ) ) )
    (close file)
)

Thảo luận gốc

Lisp được chia sẻ trong chủ đề Import text từ text file vào autocad. Xem đúng bài viết #432797 để đọc hướng dẫn và trao đổi thêm.

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