sdls
发表于 2019-3-9 22:09:29
start4444 发表于 2019-3-9 21:29
自己选肯定可以实现,就不算批量了,操作慢
谢谢解答!!
依然小小鸟
发表于 2019-3-10 10:34:29
不错的帖子顶一下
sunny_8848
发表于 2019-3-10 20:22:42
start4444 发表于 2019-3-9 21:36
http://bbs.mjtd.com/forum.php?mod=viewthread&tid=178718
参考这里,如果图框是块就好办,求得外框 ...
谢谢帮忙,可惜图框不是块,是一般的矩形
137407536
发表于 2019-4-9 14:27:49
学习了
KO你
发表于 2019-9-9 15:03:36
start4444 发表于 2019-3-8 17:03
在原代码上单独修改了横向对齐,如果要合并就用if函数搞一下就行了
(defun c:dq (/ selobjs oldcmdecho)
(setq oldcmdecho (getvar "cmdecho"))
(setvar "cmdecho" 0)
(setq selobjs (ssget))
(if (or (not selobjs) (= (sslength selobjs) 1))
(princ "\n你必须选定两个或两个以上的对象")
(process selobjs)
)
(setvar "cmdecho" oldcmdecho)
(princ)
)
(defun process (selobjs / amode apnt apnt_x
apnt_y count objname vlaxobj MinPoint
MaxPointminext maxext ext_l ext_r
ext_m tpnt
)
(initget "L M R")
(setq amode (getkword
"\n选择对齐方式[左对齐(L)/对中(M)/右对齐(R)]<左对齐>:"
)
)
(if (not amode)
(setq amode "L")
)
(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))
(cond
((= amode "L")
(setq tpnt (list ext_l apnt_y))
)
((= amode "M")
(setq tpnt (list ext_m apnt_y))
)
((= amode "R")
(setq tpnt (list ext_r apnt_y))
)
)
(if tpnt
(command "_move" objname "" "non" tpnt "non" apnt)
)
(setq count (1+ count))
)
)
(defun c:tt5 (/ selobjs oldcmdecho)
(setq oldcmdecho (getvar "cmdecho"))
(setvar "cmdecho" 0)
(setq selobjs (ssget))
(if (or (not selobjs) (= (sslength selobjs) 1))
(princ "\n你必须选定两个或两个以上的对象")
(process selobjs)
)
(setvar "cmdecho" oldcmdecho)
(princ)
)
(defun process (selobjs / amode apnt apnt_x
apnt_y count objname vlaxobj MinPoint
MaxPointminext maxext ext_l ext_r
ext_m tpnt
)
(initget "D M S")
(setq amode (getkword
"\n选择对齐方式[底对齐(D)/对中(M)/顶对齐(S)]<底对齐>:"
)
)
(if (not amode)
(setq amode "D")
)
(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 (cadr minext))
(setq ext_r (cadr maxext))
(setq ext_m (+ (/ (abs (- ext_l ext_r)) 2) ext_l))
(cond
((= amode "D")
(setq tpnt (list apnt_x ext_l))
)
((= amode "M")
(setq tpnt (list apnt_x ext_m))
)
((= amode "S")
(setq tpnt (list apnt_x ext_r))
)
)
(if tpnt
(command "_move" objname "" "non" tpnt "non" apnt)
)
(setq count (1+ count))
)
)
请问这两个程序放一起怎么只运行了Y轴的,X轴的运行读不出来什么原因呢,能不能把这两个轴的并合出一套完善的程序呢
dbgaytsy39185
发表于 2019-9-10 17:02:19
mark一下,感谢大佬分享
lidaxiu
发表于 2019-9-10 23:24:28
如果是散的对象,想对齐,就是选择集对齐,论坛里也有的
alexmai
发表于 2019-11-5 10:47:57
KO你 发表于 2019-9-9 15:03
(defun c:dq (/ selobjs oldcmdecho)
(setq oldcmdecho (getvar "cmdecho"))
(setvar "cmdecho" 0) ...
修改一下变量名称就可以合并
KO你
发表于 2019-12-11 20:18:18
alexmai 发表于 2019-11-5 10:47
修改一下变量名称就可以合并
用这个最实用了,什么对象都可以对齐
这代码是那个大师的我忘记了,我修改了一点点。
;;==============实体对齐=================
(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)
alexmai
发表于 2019-12-13 16:26:38
KO你 发表于 2019-12-11 20:18
用这个最实用了,什么对象都可以对齐
这代码是那个大师的我忘记了,我修改了一点点。
;;============== ...
确实比我的更直观,便捷 :handshake