Jump to content

Lisp lệnh GG trong chủ đề “Hỏi code lisp: Lấy text từ .txt đưa vào CAD”

Mấy ngày nay không thấy bác Tue_NV online nên tôi làm giúp cho bạn đây:

(defun c:gg ( / osm cmd tenfile file cc ccc lst pt gtri)
(command "undo" "be")
(setq osm (getvar "osmode") cmd (getvar "cmdecho"))
(setvar "osmode" 0) (setvar "cmdecho" 0)
(setq tenfile (getfiled "Chon file" "" "txt" 10))
(setq file (open tenfile "r"))
(read-line file)
(if (= (setq cc (cdr (assoc 40 (tblsearch "style" (getvar "textstyle"))))) 0)
 (setq ccc (getreal "\nChieu cao chu: ")))
(while (setq dulieu (read-line file))
 (setq lst (TUE-STR-SPLIT " " dulieu))
 (setq pt (list (nth 0 lst) (nth 1 lst)))
 (setq gtri (nth 2 lst))
 (if (= cc 0)
  (command ".text" "mc" pt ccc 0 gtri)
  (command ".text" "mc" pt 0 gtri)))
(close file)
(setvar "osmode" osm) (setvar "cmdecho" cmd)
(command "undo" "end")
(princ))
;-----
(defun Tue-str-split(sym str / i)
 (setq i (strlen str) str1 "")
 (while (= (substr str i 1) sym) (setq i (1- i)) )
 (setq str (strcat (substr str 1 (1- i)) "\")")  j (strlen str))
 (while (/= (substr str j 1) sym) (setq j (1- j)))
 (read (strcat (substr str 1 j) "\"" (substr str (1+ j) i))))

Oh, cám ơn a nhiều nhé!

Cách dùng

  1. Tải tệp 190457_gg.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 GG để chạy lisp.

Mã nguồn 190457_gg.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/61935-h%E1%BB%8Fi-code-lisp-l%E1%BA%A5y-text-t%E1%BB%AB-txt-%C4%91%C6%B0a-v%C3%A0o-cad/
(defun c:gg ( / osm cmd tenfile file cc ccc lst pt gtri)
(command "undo" "be")
(setq osm (getvar "osmode") cmd (getvar "cmdecho"))
(setvar "osmode" 0) (setvar "cmdecho" 0)
(setq tenfile (getfiled "Chon file" "" "txt" 10))
(setq file (open tenfile "r"))
(read-line file)
(if (= (setq cc (cdr (assoc 40 (tblsearch "style" (getvar "textstyle"))))) 0)
 (setq ccc (getreal "\nChieu cao chu: ")))
(while (setq dulieu (read-line file))
 (setq lst (TUE-STR-SPLIT " " dulieu))
 (setq pt (list (nth 0 lst) (nth 1 lst)))
 (setq gtri (nth 2 lst))
 (if (= cc 0)
  (command ".text" "mc" pt ccc 0 gtri)
  (command ".text" "mc" pt 0 gtri)))
(close file)
(setvar "osmode" osm) (setvar "cmdecho" cmd)
(command "undo" "end")
(princ))
;-----
(defun Tue-str-split(sym str / i)
 (setq i (strlen str) str1 "")
 (while (= (substr str i 1) sym) (setq i (1- i)) )
 (setq str (strcat (substr str 1 (1- i)) "\")")  j (strlen str))
 (while (/= (substr str j 1) sym) (setq j (1- j)))
 (read (strcat (substr str 1 j) "\"" (substr str (1+ j) i))))

Thảo luận gốc

Lisp được chia sẻ trong chủ đề Hỏi code lisp: Lấy text từ .txt đưa vào CAD. Xem đúng bài viết #190457 để đọc hướng dẫn và trao đổi thêm.

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