Lisp lệnh EB trong chủ đề “Lisp Thay Đổi Height Và Width Factor Của Text Attribute Trong Block”
Hy vọng là được (Khuyến mại thêm Textstyle): :D
(defun c:eb (/ 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)
(setq *error* (defun my-err (msg)
(cond ((= msg "function cancelled") (princ "\t\tuser abort"))
(t (progn (princ msg) (princ))))
(setq *error* nil)
(princ)))
(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;" "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" (rtos possty))
(start_list "sty" 3)
(mapcar 'add_list lststy)
(end_list)
(action_tile "accept" "(getvalue)(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
- 379567_eb.lsp
Cách dùng
- Tải tệp 379567_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 379567_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 (/ get-gc put-gc getvalue *error* att curcmd dcledittext dcl_id editext file_dcl hei oldhei oldval oldwid str wid dialog taolistlststy possty sty)(setq *error* (defun my-err (msg)(cond ((= msg "function cancelled") (princ "\t\tuser abort"))(t (progn (princ msg) (princ))))(setq *error* nil)(princ)))(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;" "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" (rtos possty))(start_list "sty" 3)(mapcar 'add_list lststy)(end_list)(action_tile "accept" "(getvalue)(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 #379567 để đọc hướng dẫn và trao đổi thêm.