;;
;;程序名称:对象水平对齐程序,并且按照竖直方向排列
;;执行命令:tb2
;;程序功能:将选定的对象左对齐,并且按照竖直方向排列。
;;
(defun c:tb2(/ selobjs oldcmdecho) ;定义命令txtal,局部变量selobjs,oldcmdecho;
(setq oldcmdecho (getvar "cmdecho")) ;oldcmdecho 存储命令回显模式
(setvar "cmdecho" ) ;屏蔽提示
(setq selobjs (ssget ' ((0 . "TEXT,MTEXT")))) ;获取文字对象?todo
(process2 selobjs) ;处理选中的对象;
(setvar "cmdecho" oldcmdecho) ;设置命令回显模式
(princ) ;todo?
)
(defun process2 (selobjs / amode apnt apnt_x
apnt_y count objname vlaxobj MinPoint
MaxPoint minext maxext ext_l ext_r
ext_m tpnt ext_y old_y countp lstp n is_del
orderlist n1
)
;; amode 对齐模式;apnt 对齐点;apnt_x 对齐点x坐标
;; apnt_y 对起点y坐标;count 计数器;
;; objname 获取图元名称 vlaxobj vla对象名
;; ext_y 原来的y坐标; old_y 上一个y坐标
;; countp 迁移位置的个数; lstp 所有的x坐标集合
;; n lstp 中的一个变量;is_del 是否删除了改对象
(if (not amode)
(setq amode "L")
)
(initget )
(setq apnt (getpoint "\n选择水平对齐方向的对齐点:"))
(setq apnt_x (car apnt)
apnt_y (cadr apnt)
)
(vl-load-com)
(setq count )
(repeat (sslength selobjs)
(setq objname (ssname selobjs count)) ;;ssname此函数将返回选择集 ss 中 index 所代表的图元名
(setq vlaxobj (vlax-ename->vla-object objname)) ;;将 AutoLISP 类型的对象名转换为 VLA 对象
(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_y (cadr minext))
(setq is_del )
(foreach n orderlist
(progn ;看看是否需要删除对象
(if (> (abs (- n ext_y)));如果4大于间距则进行删除;
(if (= is_del ) ;只需要删除一次
(setq is_del )
)
)
)
)
(if (= is_del )
(setq orderlist (cons ext_y orderlist))
)
(setq count (+ count))
)
(print "before sort....")
(print orderlist)
(setq orderlist (vl-sort orderlist (function (lambda (e1 e2) (< e1 e2)))))
(print "after sort......")
(print orderlist)
(setq count )
(setq countp )
(setq old_y ) ;初始化一个值
(repeat (sslength selobjs) ;;repeat 此函数可判别每一个 expr 并重复执行 number 所叙述的次数,
(setq objname (ssname selobjs count)) ;;ssname此函数将返回选择集 ss 中 index 所代表的图元名
(setq vlaxobj (vlax-ename->vla-object objname)) ;;将 AutoLISP 类型的对象名转换为 VLA 对象
(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)) ) ext_l))
(setq ext_y (cadr minext)) ;获取y坐标
(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))
)
)
(print old_y)
(print ext_l)
(print "=======")
(setq lstp (cons old_y lstp))
(print lstp)
(setq is_del )
(foreach n lstp
(progn ;看看是否需要删除对象
(if (> (abs (- n ext_y)));如果4大于间距则进行删除;
(if (= is_del ) ;只需要删除一次
(progn
(setq is_del )
(command "_erase" objname "") ;删除对象
(print "delete object")
)
)
)
)
)
(print "++++++++++")
(print objname)
(print is_del)
(setq countp )
(if (= is_del ) ;;如果没有删除对象
(progn ;移动对象
(setq tpnt (list ext_l ext_y));设置原来点坐标
(print tpnt)
(foreach n1 orderlist
(progn
(if (< ext_y n1)
(setq countp (+ countp));获取countp的位移
)
)
)
(print "countp now is ")
(print countp)
(setq apnt (list apnt_x (- apnt_y (* countp))));设置目标点
(print apnt)
(if tpnt
(command "_move" objname "" "non" tpnt "non" apnt)
)
;;(setq countp (+ countp))
)
) ;end if
(setq old_y ext_y) ;再一次设置old_y
(setq count (+ count))
)
)