- ;; 更改文字为左对齐
- (defun Just-Left (ent) (entmod (subst (cons 72 0) (assoc 72 ent) ent)))
- ;; 文字横向对齐
- (defun dq-hor (ss p0 dd / i boxpt lst d0 s1)
- (setq i -1)
- (repeat (sslength ss)
- (setq s1 (ssname ss (setq i (1+ i))))
- (Just-Left (entget s1)) ;文字改为左对齐
- (setq boxpt (textbox (entget s1))
- lst (cons (list
- s1
- (cdr (assoc 10 (entget s1)))
- (1+ (fix (- (nth 0 (nth 1 boxpt)) (nth 0 (nth 0 boxpt)))))
- )
- lst
- ) ;构建((图元名1 对齐点1 字长1) (图元名2 对齐点2 字长2)...)列表
- lst (vl-sort lst '(lambda (a b) (< (caadr a) (caadr b))));x向从左到右排序
- )
- )
- (setq d0 0)
- (foreach a lst
- (if (or (= dd nil)(= dd 0))
- (vla-move (vlax-ename->vla-object (nth 0 a))
- (vlax-3d-point (nth 1 a))
- (vlax-3d-point
- (list (car (nth 1 a)) (cadr p0) (caddr (nth 1 a)))
- )
- )
- (progn
- (vla-move (vlax-ename->vla-object (nth 0 a))
- (vlax-3d-point (nth 1 a))
- (vlax-3d-point
- (list (+ (car p0) d0) (cadr p0) (caddr p0))
- )
- )
- (setq d0 (+ d0 (nth 2 a) dd))
- )
- )
- )
- (princ)
- )
- ;; 文字纵向对齐
- (defun dq-ver (ss p0 dd / i boxpt lst d0 s1)
- (setq i -1)
- (repeat (sslength ss)
- (setq s1 (ssname ss (setq i (1+ i))))
- (Just-Left (entget s1)) ;文字改为左对齐
- (setq boxpt (textbox (entget s1))
- lst (cons (list
- s1
- (cdr (assoc 10 (entget s1)))
- (cdr (assoc 40 (entget s1)))
- )
- lst
- ) ;构建((图元名1 对齐点1 字高1) (图元名2 对齐点2 字高2)...)列表
- lst (vl-sort lst '(lambda (a b) (> (cadadr a) (cadadr b))));y向从上到下排序
- )
- )
- (setq d0 0)
- (foreach a lst
- (if (or (= dd nil)(= dd 0))
- (vla-move (vlax-ename->vla-object (nth 0 a))
- (vlax-3d-point (nth 1 a))
- (vlax-3d-point
- (list (car p0) (cadr (nth 1 a)) (caddr (nth 1 a)))
- )
- )
- (progn
- (vla-move (vlax-ename->vla-object (nth 0 a))
- (vlax-3d-point (nth 1 a))
- (vlax-3d-point
- (list (car p0) (- (cadr p0) d0) (caddr p0))
- )
- )
- (setq d0 (+ d0 dd))
- )
- )
- )
- )
- ;; 执行函数
- (defun c:dq ()
- (or kw (setq kw "2"))
- (or dd (setq dd 450))
- (setq kw (Ukword 1 "1 2" "[竖向对齐(1)/横向对齐(2)]" kw)
- dd (Udist 1 "" "间距<输入或鼠标直接量取>" dd nil)
- )
- (while (and (setq ss (ssget '((0 . "TEXT"))))
- (setq p0 (getpoint "\n指定对齐点: "))
- )
- (if (= kw "1")
- (dq-ver ss p0 dd)
- (dq-hor ss p0 dd)
- )
- )
- (princ)
- )
|