Lisp lệnh EB trong chủ đề “Lisp Thay Đổi Height Và Width Factor Của Text Attribute Trong Block”
Thêm màu mè là đây :D :
(defun c:eb (/ colimg get-gc put-gc getvalue *error* att curcmd dcledittext dcl_id editext file_dcl hei oldhei oldval oldwid str wid dialog taolist
lststy possty sty #color)
(setq *error* (defun my-err (msg)
(cond ((= msg "function cancelled") (princ "\t\tuser abort"))
(t (progn (princ msg) (princ))))
(setq *error* nil)
(princ)))
(defun colimg (k c)
(start_image k) (fill_image 0 0 (dimx_tile k) (dimy_tile k) c) (end_image) )
(defun get-gc (group entity) (cdr (assoc group (entget entity))))
(defun put-gc (value group entity / properties)
(setq properties (entget entity))
(setq properties (subst (cons group value) (assoc group properties) properties))
(entmod properties))
(defun getvalue ()
(setq str (get_tile "text")
hei (atof (get_tile "hei"))
wid (atof (get_tile "wid"))
sty (atoi (get_tile "sty"))))
(defun taolist (kieu / kieu nl lkq)
(setq lkq '())
(setq nl (tblnext kieu t))
(while nl (setq lkq (append lkq (list (cdr (assoc 2 nl))))) (setq nl (tblnext kieu)))
lkq)
(vl-load-com)
(setq dcledittext (list
"edit: dialog {label = \"CHANGE TEXT PROPERTIES\";initial_focus = \"text\";"
":edit_box {label = \"String:\"; allow_accept = true; edit_width = 45; key = \"text\";}" ": row {"
":edit_box {label = \"Height:\"; allow_accept = true; edit_width = 8; key = \"hei\";}"
":edit_box {label = \"Width:\"; allow_accept = true; edit_width = 8; key = \"wid\";}"
":popup_list {allow_accept = true; edit_width = 12; key = \"sty\";}" "}" "spacer_1;"
" :row {" " : text {" " label = \"Ch\U+1ECDn Color cho Text :\"; alignment =left;" "}"
" : image_button {"
" key = \"color\"; alignment = centered; height = 1.7; width = 15.0; fixed_width = false; fixed_height = true;" "}}"
"ok_cancel;}"))
(setq curcmd (getvar "cmdecho"))
(setvar "cmdecho" 0)
(while (/= (setq att (car (nentselp "\nselect attribute for edit: "))) nil)
(if (or (= (get-gc 0 att) "ATTRIB") (= (get-gc 0 att) "TEXT"))
(progn (setq oldval (get-gc 1 att)
oldhei (rtos (get-gc 40 att) 2 (getvar 'LUPREC))
oldwid (rtos (get-gc 41 att) 2 2)
oldsty (get-gc 7 att)
lststy (taolist "STYLE")
possty (vl-position oldsty lststy))
(setq editext.dcl (vl-filename-mktemp "edittext.dcl")
file_dcl (open editext.dcl "w"))
(foreach ll dcledittext (write-line ll file_dcl))
(close file_dcl)
(if (> 0 (setq dcl_id (load_dialog editext.dcl)))
(progn (alert "not found file edittext.dcl") (exit)))
(if (not (new_dialog "edit" dcl_id))
(progn (alert "not found edit dialog") (exit)))
(set_tile "text" oldval)
(set_tile "hei" oldhei)
(set_tile "wid" oldwid)
(set_tile "sty" (itoa possty))
(start_list "sty" 3)
(mapcar 'add_list lststy)
(end_list)
(setq #color (vla-get-color (vlax-ename->vla-object att))) (colimg "color" #color)
(action_tile "color" "(if (setq #color (acad_colordlg #color)) (colimg \"color\" #color))")
(action_tile "accept" "(getvalue) (vla-put-color (vlax-ename->vla-object att) #color)(setq dialog 1)(done_dialog)")
(action_tile "cancel" "(setq dialog nil)")
(start_dialog)
(unload_dialog dcl_id)
(if (eq dialog 1)
(progn (put-gc str 1 att) (put-gc hei 40 att) (put-gc wid 41 att) (put-gc (nth sty lststy) 7 att))))
(princ "select attrib/text")))
(if editext.dcl
(vl-file-delete editext.dcl))
(setvar "cmdecho" curcmd)
(setq *error* nil)
(princ))
- Tải lisp
- 381035_eb.lsp
Cách dùng
- Tải tệp 381035_eb.lsp về máy.
- 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ẽ.
- Gõ lệnh EB để chạy lisp.
Mã nguồn 381035_eb.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/150386-lisp-thay-%C4%91%E1%BB%95i-height-v%C3%A0-width-factor-c%E1%BB%A7a-text-attribute-trong-block/
(defun c:eb (/ colimg get-gc put-gc getvalue *error* att curcmd dcledittext dcl_id editext file_dcl hei oldhei oldval oldwid str wid dialog taolist
lststy possty sty #color)
(setq *error* (defun my-err (msg)
(cond ((= msg "function cancelled") (princ "\t\tuser abort"))
(t (progn (princ msg) (princ))))
(setq *error* nil)
(princ)))
(defun colimg (k c)
(start_image k) (fill_image 0 0 (dimx_tile k) (dimy_tile k) c) (end_image) )
(defun get-gc (group entity) (cdr (assoc group (entget entity))))
(defun put-gc (value group entity / properties)
(setq properties (entget entity))
(setq properties (subst (cons group value) (assoc group properties) properties))
(entmod properties))
(defun getvalue ()
(setq str (get_tile "text")
hei (atof (get_tile "hei"))
wid (atof (get_tile "wid"))
sty (atoi (get_tile "sty"))))
(defun taolist (kieu / kieu nl lkq)
(setq lkq '())
(setq nl (tblnext kieu t))
(while nl (setq lkq (append lkq (list (cdr (assoc 2 nl))))) (setq nl (tblnext kieu)))
lkq)
(vl-load-com)
(setq dcledittext (list
"edit: dialog {label = \"CHANGE TEXT PROPERTIES\";initial_focus = \"text\";"
":edit_box {label = \"String:\"; allow_accept = true; edit_width = 45; key = \"text\";}" ": row {"
":edit_box {label = \"Height:\"; allow_accept = true; edit_width = 8; key = \"hei\";}"
":edit_box {label = \"Width:\"; allow_accept = true; edit_width = 8; key = \"wid\";}"
":popup_list {allow_accept = true; edit_width = 12; key = \"sty\";}" "}" "spacer_1;"
" :row {" " : text {" " label = \"Ch\U+1ECDn Color cho Text :\"; alignment =left;" "}"
" : image_button {"
" key = \"color\"; alignment = centered; height = 1.7; width = 15.0; fixed_width = false; fixed_height = true;" "}}"
"ok_cancel;}"))
(setq curcmd (getvar "cmdecho"))
(setvar "cmdecho" 0)
(while (/= (setq att (car (nentselp "\nselect attribute for edit: "))) nil)
(if (or (= (get-gc 0 att) "ATTRIB") (= (get-gc 0 att) "TEXT"))
(progn (setq oldval (get-gc 1 att)
oldhei (rtos (get-gc 40 att) 2 (getvar 'LUPREC))
oldwid (rtos (get-gc 41 att) 2 2)
oldsty (get-gc 7 att)
lststy (taolist "STYLE")
possty (vl-position oldsty lststy))
(setq editext.dcl (vl-filename-mktemp "edittext.dcl")
file_dcl (open editext.dcl "w"))
(foreach ll dcledittext (write-line ll file_dcl))
(close file_dcl)
(if (> 0 (setq dcl_id (load_dialog editext.dcl)))
(progn (alert "not found file edittext.dcl") (exit)))
(if (not (new_dialog "edit" dcl_id))
(progn (alert "not found edit dialog") (exit)))
(set_tile "text" oldval)
(set_tile "hei" oldhei)
(set_tile "wid" oldwid)
(set_tile "sty" (itoa possty))
(start_list "sty" 3)
(mapcar 'add_list lststy)
(end_list)
(setq #color (vla-get-color (vlax-ename->vla-object att))) (colimg "color" #color)
(action_tile "color" "(if (setq #color (acad_colordlg #color)) (colimg \"color\" #color))")
(action_tile "accept" "(getvalue) (vla-put-color (vlax-ename->vla-object att) #color)(setq dialog 1)(done_dialog)")
(action_tile "cancel" "(setq dialog nil)")
(start_dialog)
(unload_dialog dcl_id)
(if (eq dialog 1)
(progn (put-gc str 1 att) (put-gc hei 40 att) (put-gc wid 41 att) (put-gc (nth sty lststy) 7 att))))
(princ "select attrib/text")))
(if editext.dcl
(vl-file-delete editext.dcl))
(setvar "cmdecho" curcmd)
(setq *error* nil)
(princ))
Thảo luận gốc
Lisp được chia sẻ trong chủ đề Lisp Thay Đổi Height Và Width Factor Của Text Attribute Trong Block. Xem đúng bài viết #381035 để đọc hướng dẫn và trao đổi thêm.