Jump to content

Lisp lệnh GT CL trong chủ đề “Nhờ sửa lip tính cốt đai và ghi vào trong dim”

Đây nè Bạn, theo đúng yêu cầu. Hết

;-------------------------------------------------------------------------------------------------------------------------
;          ==============>>  GT: TINH SL DAI VA GHI VAO DIM <<================ 
;-------------------------------------------------------------------------------------------------------------------------

(defun C:gt (/ ctc ss)
  (or *ctc* (setq *ctc* 200))
  (initget 6)
  (setq	ctc (getint
	      (strcat "\nNh\U+1EADp b\U+01B0\U+1EDBc th\U+00E9p < "
		      (itoa *ctc*)
		      ">:"
	      ) ;_ end of strcat
	    ) ;_ end of getint
  ) ;_ end of setq
  (if ctc
    (setq *ctc* ctc)
  ) ;_ end of if
  (if (setq ss (ssget "_:L" (list (cons 0 "DIMENSION"))))
    (progn
      (command "_.undo" "_begin")
      (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
	(vla-put-TextOverride
	  (vlax-ename->vla-object ent)
	  (strcat
	    "<>\\X"
;;;	    (itoa (+ (fix (/ (cdr (assoc 42 (entget ent))) *ctc*)) 1))
	    (itoa (+ (fix (/ (- (cdr (assoc 42 (entget ent)))200) *ctc*)) 1))
	    "%%c10A"
	    (itoa *ctc*)
	  ) ;_ end of strcat
	) ;_ end of vla-put-TextOverride
      ) ;_ end of foreach
      (command "_.undo" "_end")
      (princ)
    ) ;_ end of progn
  ) ;_ end of if
) ;_ end of defun
(defun C:cl (/ num ss)
  (if (setq ss (ssget "_:L"))
    (progn
      (command "_.undo" "_begin")
      (or *num* (setq *num* 15))
      (initget 4)
      (setq num (getint (strcat "\nNhap color <" (itoa *num*) ">:")))
      (while (not (if num
		    (<= num 256)
		    T
		  ) ;_ end of if
	     ) ;_ end of not
	(princ "\nGia tri <=256.")
	(setq num (getint (strcat "\nNhap color <" (itoa *num*) ">:")))
      ) ;_ end of while
      (if num
	(setq *num* num)
      ) ;_ end of if
      (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
	(vla-put-Color (vlax-ename->vla-object ent) *num*)
      ) ;_ end of foreach
      (command "_.undo" "_end")
      (princ)
    ) ;_ end of progn
  ) ;_ end of if
) ;_ end of defun

 

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 435317_gt_cl.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 GT CL để chạy lisp.

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

;-------------------------------------------------------------------------------------------------------------------------
;          ==============>>  GT: TINH SL DAI VA GHI VAO DIM <<================ 
;-------------------------------------------------------------------------------------------------------------------------

(defun C:gt (/ ctc ss)
  (or *ctc* (setq *ctc* 200))
  (initget 6)
  (setq	ctc (getint
	      (strcat "\nNh\U+1EADp b\U+01B0\U+1EDBc th\U+00E9p < "
		      (itoa *ctc*)
		      ">:"
	      ) ;_ end of strcat
	    ) ;_ end of getint
  ) ;_ end of setq
  (if ctc
    (setq *ctc* ctc)
  ) ;_ end of if
  (if (setq ss (ssget "_:L" (list (cons 0 "DIMENSION"))))
    (progn
      (command "_.undo" "_begin")
      (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
	(vla-put-TextOverride
	  (vlax-ename->vla-object ent)
	  (strcat
	    "<>\\X"
;;;	    (itoa (+ (fix (/ (cdr (assoc 42 (entget ent))) *ctc*)) 1))
	    (itoa (+ (fix (/ (- (cdr (assoc 42 (entget ent)))200) *ctc*)) 1))
	    "%%c10A"
	    (itoa *ctc*)
	  ) ;_ end of strcat
	) ;_ end of vla-put-TextOverride
      ) ;_ end of foreach
      (command "_.undo" "_end")
      (princ)
    ) ;_ end of progn
  ) ;_ end of if
) ;_ end of defun
(defun C:cl (/ num ss)
  (if (setq ss (ssget "_:L"))
    (progn
      (command "_.undo" "_begin")
      (or *num* (setq *num* 15))
      (initget 4)
      (setq num (getint (strcat "\nNhap color <" (itoa *num*) ">:")))
      (while (not (if num
		    (<= num 256)
		    T
		  ) ;_ end of if
	     ) ;_ end of not
	(princ "\nGia tri <=256.")
	(setq num (getint (strcat "\nNhap color <" (itoa *num*) ">:")))
      ) ;_ end of while
      (if num
	(setq *num* num)
      ) ;_ end of if
      (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
	(vla-put-Color (vlax-ename->vla-object ent) *num*)
      ) ;_ end of foreach
      (command "_.undo" "_end")
      (princ)
    ) ;_ end of progn
  ) ;_ end of if
) ;_ end of defun

Thảo luận gốc

Lisp được chia sẻ trong chủ đề Nhờ sửa lip tính cốt đai và ghi vào trong dim. Xem đúng bài viết #435317 để đọc hướng dẫn và trao đổi thêm.

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