Jump to content

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

Chắc bạn bấm nút để download lisp, cách này hay bị lỗi.

Hãy copy code, past vào file text rồi save thành file .lsp

code mới có vẽ khung


(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 ekLine (p q) (entmake (list '(0 . "LINE") (cons 10 p) (cons 11 q))))
(defun C:IPT( / file h i line n p r s title x x0 xn y y0)
    (setq s (getfiled "\nFile text:" "" "txt" 0))
    (setq h 2.2 ; cao text
                r 5 ; kc hang
                n '(3 2 5 6)
                x '(0 25 50 80 100);
                title '("JOINT NO." "SIZE" "DIA INCH." "QUANTITY."))
    (setq file (open s "r") p (getpoint "\nVi tri: "))
    (setq x0 (car p) y0 (cadr p) y (- y0 6)i 0 xn (+ x0 (last x)))
    (repeat 4
        (eText (list (+ x0 (* 0.5 (+ (nth i x) (nth (1+ i) x)))) y) h (nth i title) 1 1)
        (setq i (1+ i))
    )
    (ekLine p (mapcar '+ p (list (last x) 0 )))
    (setq y (- y 2))
    (ekLine (list x0 y) (list xn y))
    (while (setq s (read-line file))
        (setq line (read (strcat "(" s ")")))
        (if (>= (length line) 6)
            (progn
                (setq i 0 y (- y r))
                (repeat 4
                    (eText (list (+ x0 -10 (nth (1+ i) x)) y) h (itoa(nth (nth i n) line)) 2 1)
                    (setq i (1+ i))
    ) ) ) )
    (close file)
    (setq y (- y 2))
    (ekLine (list x0 y) (list xn y))
    (foreach e x
        (ekLine (list (+ e x0) y0) (list (+ e x0) y))    )
)

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

  1. Chép mã nguồn, lưu thành tệp 432814_ipt.lsp.
  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 432814_ipt.lsp (trích từ bài viết gốc)

(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 ekLine (p q) (entmake (list '(0 . "LINE") (cons 10 p) (cons 11 q))))
(defun C:IPT( / file h i line n p r s title x x0 xn y y0)
    (setq s (getfiled "\nFile text:" "" "txt" 0))
    (setq h 2.2 ; cao text
                r 5 ; kc hang
                n '(3 2 5 6)
                x '(0 25 50 80 100);
                title '("JOINT NO." "SIZE" "DIA INCH." "QUANTITY."))
    (setq file (open s "r") p (getpoint "\nVi tri: "))
    (setq x0 (car p) y0 (cadr p) y (- y0 6)i 0 xn (+ x0 (last x)))
    (repeat 4
        (eText (list (+ x0 (* 0.5 (+ (nth i x) (nth (1+ i) x)))) y) h (nth i title) 1 1)
        (setq i (1+ i))
    )
    (ekLine p (mapcar '+ p (list (last x) 0 )))
    (setq y (- y 2))
    (ekLine (list x0 y) (list xn y))
    (while (setq s (read-line file))
        (setq line (read (strcat "(" s ")")))
        (if (>= (length line) 6)
            (progn
                (setq i 0 y (- y r))
                (repeat 4
                    (eText (list (+ x0 -10 (nth (1+ i) x)) y) h (itoa(nth (nth i n) line)) 2 1)
                    (setq i (1+ i))
    ) ) ) )
    (close file)
    (setq y (- y 2))
    (ekLine (list x0 y) (list xn y))
    (foreach e x
        (ekLine (list (+ e x0) y0) (list (+ e x0) y))    )
)

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 #432814 để đọc hướng dẫn và trao đổi thêm.

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