 - ;;******************************************************
- ;; 文字对齐
- ;;******************************************************
- ;;源码来源明经社区,最终由xvjiex修改 2021.07.02
- (defun c:wzdq (/ ss ent amode obj i ii p px jd jdx jdy ang th1)
- (setvar "cmdecho" 0)
- ;;-------------------------
- (defun getdxf (ent ii)
- (if (= (type ent) 'ename)
- (setq ent (entget ent))
- )
- (cdr (assoc ii ent))
- )
- ;;-------------------------
- (defun ch_dxf (en num ch / old_num new_num ent)
- (if
- (setq ent (entget en)
- new_num (cons num ch)
- old_num (assoc num ent)
- )
- (entmod (subst new_num old_num ent))
- (entmod (reverse (cons new_num (reverse ent))))
- )
- )
- ;;-------------------------
- (or dis(setq dis 50))
- (setq th1 (getreal (strcat"\n请输入对齐基点与对齐点固定距离<"(rtos dis 2 3)">:")))
- (if th1 (setq dis th1))
- (princ "\n选择要对齐的文字<退出>:")
- (if (setq ss (ssget '((0 . "TEXT"))))
- (progn
- (setq p (getpoint "指定对齐基点:"))
- (setq px (car p)
- py (cadr p)
- );;基点x和y坐标
- (initget "L C R")
- (setq amode (getkword "\n选择对齐方式[左(L)/中(C)/右(R)]<左>:"))
- (if (not amode)
- (setq amode "L")
- )
- (cond
- ((= amode "L")
- (setq ii 10)
- (command "justifytext" ss "" "L")
- )
- ((= amode "C")
- (setq ii 11)
- (command "justifytext" ss "" "C")
- )
- ((= amode "R")
- (setq ii 11)
- (command "justifytext" ss "" "R")
- )
- )
- (setq i 0)
- (while (< i (sslength ss))
- (setq ent (ssname ss i))
- (setq jd (getdxf ent ii))
- (setq jdx (car jd)
- jdy (cadr jd)
- )
- (princ )
- ;;;;;;;;;;;;;;;以下为添加代码 by whuluqw
- (setq ang (getdxf ent 50)) ;;获取文字转角
- (setq dx (- jdx px)
- dy (- jdy py)
- ) ;;指定对齐点和文字基点距离
- (setq dx2 (-(+ (* dx (cos ang)) (* dy (sin ang)))dis)
- dy2 (- (* dy (cos ang)) (* dx (sin ang)))
- ) ;;求移动距离
- (setq newx (- jdx (* dx2 (cos ang)))
- newy (- jdy (* dx2 (sin ang)))
- )
- ;;;;;;;;;;;;;;以上为添加代码
- (setq newjd (list newx newy))
- (apply '(lambda (x) (ch_dxf x ii newjd)) (list ent))
- ;(vl-cmdf "_move" (ssname ss i) "" "non" jd "non" (list px jdy))
- (setq i (+ i 1))
- )
- )
- )
- (princ)
- )
|