本帖最后由 kozmosovia 于 2016-3-31 20:44 编辑
直接将边界图形与文字全选,自动判断边界图形的左右边
- (Defun C:AdjText ( / _GetLeftRight ALI D40 EPT I LR NN SN SS SPT ST TXT)
- (Defun _GetLeftRight (obj / LL UR)
- (vla-getboundingbox (vlax-ename->vla-object obj) 'll 'ur)
- (setq ll (trans (vlax-safearray->list ll) 0 1)
- ur (trans (vlax-safearray->list ur) 0 1)
- )
- (list (car ll) (car ur))
- )
- (if (setq i -1
- d40 0.0
- lr (list 1e99 -1e99)
- ss (ssget '((0 . "text,arc,circle,*line")))
- )
- (progn
- (repeat (sslength ss)
- (setq sn (ssname ss (setq i (1+ i)))
- st (cdr (assoc 0 (entget sn)))
- )
- (if (= st "TEXT")
- (setq d40 (max d40 (cdr (assoc 40 (entget sn))))
- txt (cons sn txt)
- )
- (setq nn (_GetLeftRight sn)
- lr (list (min (car lr) (car nn))
- (max (cadr lr) (cadr nn))
- )
- )
- )
- )
- (initget "Left Middle Right")
- (setq
- ali (getkword "\n Enter Alignment [Left/Middle/Right] <M>:")
- )
- (if (null ali)
- (setq ali "Middle")
- )
- (setq d40 (* 0.5 d40))
- (foreach sn txt
- (setq nn (_GetLeftRight sn))
- (cond ((= ali "Left")
- (setq spt (car nn)
- ept (+ d40 (car lr))
- )
- )
- ((= ali "Middle")
- (setq spt (* 0.5 (+ (car nn) (cadr nn)))
- ept (* 0.5 (+ (car lr) (cadr lr)))
- )
- )
- ((= ali "Right")
- (setq spt (cadr nn)
- ept (- (cadr lr) d40)
- )
- )
- )
- (command "_.Move" sn "" (list spt 0. 0.) (list ept 0. 0.))
- )
- )
- )
- )
|