Jump to content

Lisp thay đổi chiều cao text của dimstyle cực nhanh !

 

Làm dâu trăm họ smile.gif

Thôi thì theo cái lisp cũ, mình viết thêm vài kiểu nữa cho chắc :

1. Change cho toàn bộ DimStyle trong bản vẽ :

(defun c:hdima (/ table tH)
(grtext -1 "Free lisp from Cadviet @Ketxu")
(command "undo" "be")
(defun table (s / d r)
(while (setq d (tblnext s (null d)))
(setq r (cons (cdr (assoc 2 d)) r))
)
)
(setq tH (getreal "\n Text Height :"))
(setvar "cmdecho" 0)
(mapcar '(lambda(x)(command "DIMSTYLE" "R" x)(setvar "DIMTXT" tH)(command "DIMSTYLE" "S" x "Y")) (table "DIMSTYLE"))
(command "undo" "en"))
2. Pick đến đâu change đến đó :

(defun c:hdimb (/ lstDstyle tH ent dstyle)
(grtext -1 "Free lisp from Cadviet @Ketxu")
(command "undo" "be")
(setvar "cmdecho" 0)
(setq tH (getreal "\n Text Height :"))
(while (setq ent (car (entsel "\n Pick dim :")))
	(if (setq dstyle (cdr (assoc 3 (entget ent))))
		(if (not (vl-position dstyle lstDstyle))
			(progn
				(setq lstDstyle (cons dstyle lstDstyle))
				(command "DIMSTYLE" "R" dstyle)(setvar "DIMTXT" tH)(command "DIMSTYLE" "S" dstyle "Y")
			)
			(princ "\nAlready Dimension Style Picked")
		)
	)
)
(command "undo" "en")
)
3. Chọn 1 loạt rồi change :

(defun c:hdimc (/ lstDstyle tH i ss ent dstyle)
(grtext -1 "Free lisp from Cadviet @Ketxu")
(command "undo" "be")
(setvar "cmdecho" 0)
(setq tH (getreal "\n Text Height :") i 0 ss (ssget (list (cons 0 "DIMENSION"))))
(while (setq ent (ssname ss i))	
	(if (setq dstyle (cdr (assoc 3 (entget ent))))
		(if (not (vl-position dstyle lstDstyle))
			(progn
				(setq lstDstyle (cons dstyle lstDstyle))
				(command "DIMSTYLE" "R" dstyle)(setvar "DIMTXT" tH)(command "DIMSTYLE" "S" dstyle "Y")
			)			
		)
	)
	(setq i (1+ i))
)
(command "undo" "en")
)
Đó là công việc mà mọi người trên diễn đàn đang cố gắng làm và chia sẻ bạn à smile.gif

lips hay nhưng mình nhập chiều cao 1 đằng thì chiều cao thực tế của text dim lại kiểu khác bạn ah.

 

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 295904_hdimc.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 HDIMC để chạy lisp.

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

(defun c:hdima (/ table tH)
(grtext -1 "Free lisp from Cadviet @Ketxu")
(command "undo" "be")
(defun table (s / d r)
(while (setq d (tblnext s (null d)))
(setq r (cons (cdr (assoc 2 d)) r))
)
)
(setq tH (getreal "\n Text Height :"))
(setvar "cmdecho" 0)
(mapcar '(lambda(x)(command "DIMSTYLE" "R" x)(setvar "DIMTXT" tH)(command "DIMSTYLE" "S" x "Y")) (table "DIMSTYLE"))
(command "undo" "en"))

(defun c:hdimb (/ lstDstyle tH ent dstyle)
(grtext -1 "Free lisp from Cadviet @Ketxu")
(command "undo" "be")
(setvar "cmdecho" 0)
(setq tH (getreal "\n Text Height :"))
(while (setq ent (car (entsel "\n Pick dim :")))
	(if (setq dstyle (cdr (assoc 3 (entget ent))))
		(if (not (vl-position dstyle lstDstyle))
			(progn
				(setq lstDstyle (cons dstyle lstDstyle))
				(command "DIMSTYLE" "R" dstyle)(setvar "DIMTXT" tH)(command "DIMSTYLE" "S" dstyle "Y")
			)
			(princ "\nAlready Dimension Style Picked")
		)
	)
)
(command "undo" "en")
)

(defun c:hdimc (/ lstDstyle tH i ss ent dstyle)
(grtext -1 "Free lisp from Cadviet @Ketxu")
(command "undo" "be")
(setvar "cmdecho" 0)
(setq tH (getreal "\n Text Height :") i 0 ss (ssget (list (cons 0 "DIMENSION"))))
(while (setq ent (ssname ss i))	
	(if (setq dstyle (cdr (assoc 3 (entget ent))))
		(if (not (vl-position dstyle lstDstyle))
			(progn
				(setq lstDstyle (cons dstyle lstDstyle))
				(command "DIMSTYLE" "R" dstyle)(setvar "DIMTXT" tH)(command "DIMSTYLE" "S" dstyle "Y")
			)			
		)
	)
	(setq i (1+ i))
)
(command "undo" "en")
)

Thảo luận gốc

Lisp được chia sẻ trong chủ đề [yêu cầu] Lisp thay đổi chiều cao text của dimstyle cực nhanh !. Xem đúng bài viết #295904 để đọc hướng dẫn và trao đổi thêm.

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