xinxirong 发表于 2016-5-10 10:53:20

如何获得多行文字实际内容的最小包围框

vla-getboundingbox获得的是控制点,不是实际内容的最小包围框,如果控制点范围很大,内容很少,得到的包围框就偏差较大。

kozmosovia 发表于 2016-5-10 13:09:00

;;;;;;;;;;;;;;;;;;;;;;; KozMos AnnoQuarX Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Name:                AQX:GETMTEXTBOX(2)                                                        ;;;
;;; Descryption:        Get the boundary rectangle box of the MTEXT/TEXT                        ;;;
;;; Argu(1):                The annotation object selectionset                        ENAME                ;;;
;;; Argu(2):                Offset distance, nil for 0.0                                REAL                ;;;
;;; ------------------------------------------------------------------------------------------- ;;;
;;; RetValue(OK)        4-Points-list (LL, LR, UR, UL)                                LIST                ;;;
;;; RetValue(FAIL)        NIL                                                        BOOLEAN                ;;;
;;; ------------------------------------------------------------------------------------------- ;;;
;;; Example                (AQX:GETMTEXTBOX (car(entsel)) 0.0)                                        ;;;
;;;                ====>        ((97346.9 291.883) (61132.6 20869.7) (56983.4 13567.6) (93197.6 -7010.23));
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 2014/11/28 (Koz Jono Yeoh) ;;;;;;;;
(Defun AQX:GETMTEXTBOX (obj off / MXV B ENX H J L M N O P R W)
(Defun mxv (m v)
    (mapcar '(lambda (r) (apply '+ (mapcar '* r v))) m)
)
(setq enx (entget obj))
(if (null off)
    (setq off 0.0)
)
(if
    (setq l
           (cond
             ((= "TEXT" (cdr (assoc 0 enx)))
              (setq b (cdr (assoc 10 enx))
                  r (cdr (assoc 50 enx))
                  l (textbox enx)
              )
              (list
                (list (- (caar l) off) (- (cadar l) off))
                (list (+ (caadr l) off) (- (cadar l) off))
                (list (+ (caadr l) off) (+ (cadadr l) off))
                (list (- (caar l) off) (+ (cadadr l) off))
              )
             )
             ((= "MTEXT" (cdr (assoc 0 enx)))
              (setq n (cdr (assoc 210 enx))
                  b (trans (cdr (assoc 10 enx)) 0 n)
                  r (angle '(0.0 0.0 0.0) (trans (cdr (assoc 11 enx)) 0 n))
                  w (cdr (assoc 42 enx))
                  h (cdr (assoc 43 enx))
                  j (cdr (assoc 71 enx))
                  o (list
                        (cond
                          ((member j '(2 5 8)) (/ w -2.0))
                          ((member j '(3 6 9)) (- w))
                          (0.0)
                        )
                        (cond
                          ((member j '(1 2 3)) (- h))
                          ((member j '(4 5 6)) (/ h -2.0))
                          (0.0)
                        )
                      )
              )
              (list
                (list (- (car o) off) (- (cadr o) off))
                (list (+ (car o) w off) (- (cadr o) off))
                (list (+ (car o) w off) (+ (cadr o) h off))
                (list (- (car o) off) (+ (cadr o) h off))
              )
             )
           )
    )
   ((lambda (m)
        (mapcar '(lambda (p) (mapcar '+ (mxv m p) b)) l)
      )
       (list
       (list (cos r) (sin (- r)) 0.0)
       (list (sin r) (cos r) 0.0)
       '(0.0 0.0 1.0)
       )
   )
)
)

danxingpen 发表于 2016-5-10 12:02:05

参考textbox

USER2128 发表于 2016-5-10 11:10:29

copy、explode、vla-getboundingbox、erase

highflybird 发表于 2016-5-10 11:18:22

mtext 炸开后字体可能会发生变化,因此楼上这个方法可能不准。

xinxirong 发表于 2018-5-3 08:39:47

ros字体不对

bskidtf 发表于 2024-5-28 23:57:06

多行文字有专门的方法,
页: [1]
查看完整版本: 如何获得多行文字实际内容的最小包围框