(求助)如何框选实现黑体或其它字体水平及垂直居中于矩形框
请教一下各位大神,我在论坛上找了文字对齐的插件,然后,没有看到过水平及垂直居中的插件,也试过自己去尝试去修改,然后没有成功,所以特来请教各位大神,如何实现?只想要一个功能把“水平居中x轴\垂直居中y轴”结合起来,1.选择需要居中的文字: 2.选择需要居中的矩形: 最终结果就是文字居中于矩形框内
谢谢各位大神了
下面是参考的代码及原贴链接:
http://bbs.mjtd.com/thread-179101-2-1.html
(defun process (amode / apnt apnt_x apnt_y count objname vlaxobj MinPoint MaxPoint
minext maxext ext_l ext_r ext_m ext_vt ext_vd ext_vm tpnt)
(setq oldcmdecho (getvar "cmdecho"))
(setvar "cmdecho" 0)
(setq selobjs (ssget))
(if (or (not selobjs) (= (sslength selobjs) 1))
(princ "\n你必须选定两个或两个以上的对象")
)
(initget 1)
(setq apnt (getpoint "\n选择对齐点:"))
(setq apnt_x (car apnt)
apnt_y (cadr apnt))
(vl-load-com)
(setq count 0)
(repeat (sslength selobjs)
(setq objname (ssname selobjs count))
(setq vlaxobj (vlax-ename->vla-object objname))
(setq MinPoint (vlax-make-variant))
(setq MaxPoint (vlax-make-variant))
(vla-GetBoundingBox vlaxobj 'MinPoint 'MaxPoint)
(setq minext (vlax-safearray->list MinPoint))
(setq maxext (vlax-safearray->list MaxPoint))
(setq ext_l (car minext))
(setq ext_r (car maxext))
(setq ext_m (+ (/ (abs (- ext_l ext_r)) 2) ext_l))
(setq ext_vd (cadr minext))
(setq ext_vt (cadr maxext))
(setq ext_vm (+ (/ (abs (- ext_vt ext_vd)) 2) ext_vd))
(cond
((= amode "HL") (setq tpnt (list ext_l apnt_y)))
((= amode "HM") (setq tpnt (list ext_m apnt_y)))
((= amode "HR") (setq tpnt (list ext_r apnt_y)))
((= amode "VT") (setq tpnt (list apnt_x ext_vt)))
((= amode "VM") (setq tpnt (list apnt_x ext_vm)))
((= amode "VD") (setq tpnt (list apnt_x ext_vd)))
)
(if tpnt (command "_move" objname "" "non" tpnt "non" apnt))
(setq count (1+ count))
)
(setvar "cmdecho" oldcmdecho)
)
(defun c:ad ()
(if (> (setq dcl_id (load_dialog (setq Dcl_File (Write_Dcl_dq)))) 0)
(progn
(vl-file-delete Dcl_File);加载后删除DCL文件
(if (new_dialog "dq" dcl_id "")
(progn
(action_tile "hl" "(done_dialog 1)")
(action_tile "hm" "(done_dialog 2)")
(action_tile "hr" "(done_dialog 3)")
(action_tile "vt" "(done_dialog 4)")
(action_tile "vm" "(done_dialog 5)")
(action_tile "vd" "(done_dialog 6)")
(action_tile "cancel" "(done_dialog 0)")
(setq re (start_dialog))
)
(princ "\n无法显示对话框!")
)
(unload_dialog dcl_id)
)
(princ "\n无法加载对话框!")
)
(cond
((= re 1) (process "HL"))
((= re 2) (process "HM"))
((= re 3) (process "HR"))
((= re 4) (process "VT"))
((= re 5) (process "VM"))
((= re 6) (process "VD"))
)
(princ)
)
(defun Write_Dcl_dq(/ Dcl_File file str)
(setq Dcl_File (vl-filename-mktemp nil nil ".Dcl"))
(setq file (open Dcl_File "w"))
(foreach str '(
"dq:dialog{"
" label=\"实体对齐\";"
" :row{"
":button{label=\" 左对齐x轴 \";key=\"hl\";width=13;height=2.5;allow_accept=true;}"
":button{label=\"水平居中x轴\";key=\"hm\";width=13;height=2.5;allow_accept=true;}"
":button{label=\" 右对齐x轴 \";key=\"hr\";width=13;height=2.5;allow_accept=true;}"
" }"
" :row{"
":button{label=\" 上对齐y轴 \";key=\"vt\";width=13;height=2.5;allow_accept=true;}"
":button{label=\"垂直居中y轴\";key=\"vm\";width=13;height=2.5;allow_accept=true;}"
":button{label=\" 下对齐y轴 \";key=\"vd\";width=13;height=2.5;allow_accept=true;}"
" }"
":button{label=\" 关闭 \";key=\"cancel\";width=13;height=2.2;is_cancel=true;fixed_width=true;alignment=centered;}"
"}"
)
(write-line str file)
)
(close file)
Dcl_File
)
(princ)
TextALign 命令了解一下先。 e2002 发表于 2020-10-18 15:37
TextALign 命令了解一下先。
好的,,
页:
[1]