Jump to content

Lisp lệnh XX trong chủ đề “CẢI TIẾN LISP GÁN CONTENT CHO TEXT”

lisp gán diện tích khác hoàn toàn lisp này. Bạn dùng lisp sau đã có đổi màu cho text

(defun c:xx (/ strl e len txt fn fid)
  (vl-load-com)
  (or color (setq color 256))		; mau theo layer
  (initget 4)
  (setq	color
	 (cond
	   ((getint
	      (strcat "\nChon mau text 0-256 (0:Byblock, 256:Bylayer) <"
		      (rtos color 2 0)
		      ">: "
	      ) ;_ end of strcat
	    ) ;_ end of getint
	   )
	   (color)
	 ) ;_ end of cond
  ) ;_ end of setq


  (while
    (and (setq e (car (entsel "\n Chon pline can ghi chieu dai ")))
	 (setq
	   len (vlax-curve-getdistatparam e (vlax-curve-getendparam e))
	 ) ;_ end of setq
	 (setq txt
		(car
		  (entsel
		    "\n Chon text can ghi bo xung gia tri chieu dai polyline"
		  ) ;_ end of entsel
		) ;_ end of car
	 ) ;_ end of setq
    ) ;_ end of and
     (setq txt (vlax-ename->vla-object txt))
     (vla-put-textstring
       txt
       (strcat (vla-get-textstring txt) " " (rtos len 2 0))
     ) ;_ end of vla-put-textstring
     (vla-put-color txt color)
     (setq strl (append strl (list (rtos len 2 0))))
  ) ;_ end of while
  (if (and strl
	   (setq fn (getfiled "Chon file de save" "" "csv" 1))
      ) ;_ end of and
    (progn
      (setq fid	(open fn "w")
      ) ;_ end of setq
      (foreach str strl
	(write-line str fid)
      ) ;_ end of foreach
      (close fid)
    ) ;_ end of progn
  ) ;_ end of if
) ;_ end of defun

 

Cách dùng

  1. Tải tệp 430956_xx.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 XX để chạy lisp.

Mã nguồn 430956_xx.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/174318-c%E1%BA%A3i-ti%E1%BA%BFn-lisp-g%C3%A1n-content-cho-text/
(defun c:xx (/ strl e len txt fn fid)
  (vl-load-com)
  (or color (setq color 256))		; mau theo layer
  (initget 4)
  (setq	color
	 (cond
	   ((getint
	      (strcat "\nChon mau text 0-256 (0:Byblock, 256:Bylayer) <"
		      (rtos color 2 0)
		      ">: "
	      ) ;_ end of strcat
	    ) ;_ end of getint
	   )
	   (color)
	 ) ;_ end of cond
  ) ;_ end of setq


  (while
    (and (setq e (car (entsel "\n Chon pline can ghi chieu dai ")))
	 (setq
	   len (vlax-curve-getdistatparam e (vlax-curve-getendparam e))
	 ) ;_ end of setq
	 (setq txt
		(car
		  (entsel
		    "\n Chon text can ghi bo xung gia tri chieu dai polyline"
		  ) ;_ end of entsel
		) ;_ end of car
	 ) ;_ end of setq
    ) ;_ end of and
     (setq txt (vlax-ename->vla-object txt))
     (vla-put-textstring
       txt
       (strcat (vla-get-textstring txt) " " (rtos len 2 0))
     ) ;_ end of vla-put-textstring
     (vla-put-color txt color)
(vla-put-color (vlax-ename->vla-object e) color)
     (setq strl (append strl (list (rtos len 2 0))))
  ) ;_ end of while
  (if (and strl
	   (setq fn (getfiled "Chon file de save" "" "csv" 1))
      ) ;_ end of and
    (progn
      (setq fid	(open fn "w")
      ) ;_ end of setq
      (foreach str strl
	(write-line str fid)
      ) ;_ end of foreach
      (close fid)
    ) ;_ end of progn
  ) ;_ end of if
(princ)
) ;_ end of defun

Thảo luận gốc

Lisp được chia sẻ trong chủ đề CẢI TIẾN LISP GÁN CONTENT CHO TEXT. Xem đúng bài viết #430956 để đọc hướng dẫn và trao đổi thêm.

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