;; ;;程序名称:对象水平对齐程序 ;;执行命令:TXTAL ;;程序功能:将选定的对象左对齐、右对齐或对中。 ;; (defun c:TXTAL(/ selobjs oldcmdecho) ;定义命令txtal,局部变量selobjs,oldcmdecho; (setq oldcmdecho (getvar "cmdecho")) ;oldcmdecho 存储命令回显模式 (setvar "cmdecho" 0) ;屏蔽提示 (setq selobjs (ssget ' ((0 . "TEXT,MTEXT")))) ;获取文字对象?todo (process selobjs) ;处理选中的对象; (setvar "cmdecho" oldcmdecho) ;设置命令回显模式 (princ) ;todo? ) (defun process (selobjs / amode apnt apnt_x apnt_y count objname vlaxobj MinPoint MaxPoint minext maxext ext_l ext_r ext_m tpnt ) ;; amode 对齐模式;apnt 对齐点;apnt_x 对齐点x坐标 ;; apnt_y 对起点y坐标;count 计数器; ;; objname 获取图元名称 vlaxobj vla对象名 (initget "L M R") (setq amode (getkword " 选择对齐方式<左对齐(L)/居中(M)/右对齐(R)><左对齐>:" ) ) (if (not amode) (setq amode "L") ) (initget 1) (setq apnt (getpoint " 选择水平对齐方向的对齐点:")) (setq apnt_x (car apnt) apnt_y (cadr apnt) ) (vl-load-com) (setq count 0) (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)) 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)) ) )