Jump to content

Lisp lệnh LAYT trong chủ đề “Lisp thay thế 1 cột Text trong Excel thay Thế các Text theo thứ tự được chọn trong Cad”

Gửi bạn xem đã ok chưa????

(defun C:layt (/ oldos s text ndtext)
 (command "undo" "be")
 (setq oldos (getvar "OSMODE")) 
 (setvar "cmdecho" 0)
 (setvar "osmode" 512)
 (setq s (GetClipBoardText))
 (setq ndtext nil)
 (while (vl-string-search "\n" s)
 (setq text (substr s 1 (vl-string-search "\n" s)))
 (setq ndtext (cons (substr text 1 (- (strlen text) 1)) ndtext))
 (setq s (substr s (+ 2 (vl-string-search "\n" s))))
 )
 (setq ndtext (reverse ndtext))
 (foreach lst ndtext
 (thaythe lst)
 )
 (setvar "osmode" oldos)
 (setvar "cmdecho" 1)
 (command "undo" "end")	
 (princ )
 )
(defun thaythe(s / giatrimoi giatricu thongtin)
(setq giatriold (entsel "\nGia tri can thay the"))
	(while
 	 (or
   	 (null giatriold)
   	 (/= "TEXT" (cdr (assoc 0 (entget (car giatriold)))))
	 )
	(princ "\nDoi tuong khong phai la text! Chon lai")
 	(setq giatriold (entsel "\nGia tri can thay the"))
	)
(setq thongtin (entget (car giatriold)))
(setq giatricu (assoc 1 thongtin))
(setq giatrimoi (cons 1  s))
(setq thongtin (subst giatrimoi giatricu thongtin))
(entmod thongtin)
(command "_change" giatriold "" "p" "c" "1" "")
)
(defun GetClipBoardText( / htmlfile result ) ; By Patrick_35
 (setq htmlfile (vlax-create-object "htmlfile")
result (vlax-invoke (vlax-get (vlax-get htmlfile 'ParentWindow ) 'ClipBoardData) 'GetData "Text" ) )
 (vlax-release-object htmlfile)
 result
)

 

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 424817_layt.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 LAYT để chạy lisp.

Mã nguồn 424817_layt.lsp (trích từ bài viết gốc)

(defun C:layt (/ oldos s text ndtext)
 (command "undo" "be")
 (setq oldos (getvar "OSMODE")) 
 (setvar "cmdecho" 0)
 (setvar "osmode" 512)
 (setq s (GetClipBoardText))
 (setq ndtext nil)
 (while (vl-string-search "\n" s)
 (setq text (substr s 1 (vl-string-search "\n" s)))
 (setq ndtext (cons (substr text 1 (- (strlen text) 1)) ndtext))
 (setq s (substr s (+ 2 (vl-string-search "\n" s))))
 )
 (setq ndtext (reverse ndtext))
 (foreach lst ndtext
 (thaythe lst)
 )
 (setvar "osmode" oldos)
 (setvar "cmdecho" 1)
 (command "undo" "end")	
 (princ )
 )
(defun thaythe(s / giatrimoi giatricu thongtin)
(setq giatriold (entsel "\nGia tri can thay the"))
	(while
 	 (or
   	 (null giatriold)
   	 (/= "TEXT" (cdr (assoc 0 (entget (car giatriold)))))
	 )
	(princ "\nDoi tuong khong phai la text! Chon lai")
 	(setq giatriold (entsel "\nGia tri can thay the"))
	)
(setq thongtin (entget (car giatriold)))
(setq giatricu (assoc 1 thongtin))
(setq giatrimoi (cons 1  s))
(setq thongtin (subst giatrimoi giatricu thongtin))
(entmod thongtin)
(command "_change" giatriold "" "p" "c" "1" "")
)
(defun GetClipBoardText( / htmlfile result ) ; By Patrick_35
 (setq htmlfile (vlax-create-object "htmlfile")
result (vlax-invoke (vlax-get (vlax-get htmlfile 'ParentWindow ) 'ClipBoardData) 'GetData "Text" ) )
 (vlax-release-object htmlfile)
 result
)

Thảo luận gốc

Lisp được chia sẻ trong chủ đề Lisp thay thế 1 cột Text trong Excel thay Thế các Text theo thứ tự được chọn trong Cad. Xem đúng bài viết #424817 để đọc hướng dẫn và trao đổi thêm.

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