Jump to content

Retrieving mtext properties from a dimension (ssget)


Recommended Posts

Posted

I want to able to select multiple dimensions and add a revision cloud around the text. How do I get the properties of the mtext with without using nentsel?

Posted

This may give you some inspiration, I modified it to be able to frame Dimension Text :)

 

;;-----------------------=={ Box Text }==---------------------;;
;;                                                            ;;
;;  Frames Text, MText or Dimension Text objects with an      ;;
;;  LWPolyline, with optional offset. Works in all UCS/Views. ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2010 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;

(defun c:BT nil (c:BoxText))

(defun c:BoxText nil
 ;; © Lee Mac 2010

 (
   (lambda ( ss off i / e d )
     (if ss
       (while (setq e (ssname ss (setq i (1+ i))))
         
         (if (and (wcmatch (cdr (assoc 0 (entget e))) "*DIMENSION")
                  (setq d  (car (nentselp (trans (cdr (assoc 11 (entget e))) e 1))))
                  (wcmatch (cdr (assoc 0 (entget d))) "TEXT,MTEXT")
             )
           (setq e d) (setq e nil)                
         )
         
         (if e
           (entmakex
             (append
               (list
                 (cons 0 "LWPOLYLINE")
                 (cons 100 "AcDbEntity")
                 (cons 100 "AcDbPolyline")
                 (assoc 8 (entget e))
                 (cons 90 4)
                 (cons 70 1)
                 (cons 38 (caddr (cdr (assoc 10 (entget e)))))
                 (assoc 210 (entget e))
               )
               (mapcar '(lambda ( x ) (cons 10 x)) (LM:GetTextBox e off))
             )
           )
         )
       )
     )
   )
   (ssget '((0 . "TEXT,MTEXT,*DIMENSION")))
   (setq *o*
     (cond
       (
         (getdist
           (strcat "\nSpecify Offset <"
             (rtos
               (setq *o*
                 (cond ( *o* ) ( (* 0.5 (getvar 'TEXTSIZE)) ))
               )
             )
             "> : "
           )
         )
       )
       ( *o* )
     )
   )
   -1
 )

 (princ)
)

;;---------------------=={ Get Text Box }==-------------------;;
;;                                                            ;;
;;  Returns a point list describing a rectangle framing the   ;;
;;  specified text or mtext entity with optional offset       ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2010 - www.lee-mac.com       ;;
;;  <Inspired by Gilles Chanteau>                             ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  ent - Text or MText ename                                 ;;
;;  off - offset (may be zero)                                ;;
;;------------------------------------------------------------;;
;;  Returns:  List of Points (in OCS) describing text frame   ;;
;;------------------------------------------------------------;;

(defun LM:GetTextBox ( ent off / dx lst base rotn norm w h matrix )
 ;; © Lee Mac 2010

 (setq dx (lambda ( x l ) (cdr (assoc x l))))

 (if
   (setq lst
     (cond
       (
         (eq "TEXT" (dx 0 (setq l (entget ent))))

         (setq base (dx 10 l) rotn (dx 50 l))

         (
           (lambda ( data )
             (mapcar
               (function
                 (lambda ( funcs )
                   (mapcar
                     (function
                       (lambda ( func )
                         ((eval (car func)) ((eval (cdr func)) data) off)
                       )
                     )
                     funcs
                   )
                 )
               )
               (list
                 (list (cons '- 'caar ) (cons '- 'cadar ))
                 (list (cons '+ 'caadr) (cons '- 'cadar ))
                 (list (cons '+ 'caadr) (cons '+ 'cadadr))
                 (list (cons '- 'caar ) (cons '+ 'cadadr))
               )
             )
           )
           (textbox l)
         )
       )
       (
         (eq "MTEXT" (dx 0 l))

         (setq norm (dx 210 l) base (trans (dx 10 l) 0 norm)
        
               rotn (angle '(0. 0. 0.) (trans (dx 11 l) 0 norm))

               w (dx 42 l) h (dx 43 l)
         )
         (
           (lambda ( org )
             (mapcar
               (function
                 (lambda ( o ) (mapcar '+ org o))
               )
               (list
                 (list (-   off) (-   off))
                 (list (+ w off) (-   off))
                 (list (+ w off) (+ h off))
                 (list (-   off) (+ h off))
               )
             )
           )
           (
             (lambda ( j )
               (list
                 (cond
                   (
                     (member j '(2 5 ) (/ w -2.)
                   )
                   (
                     (member j '(3 6 9)) (- w)
                   )
                   ( 0. )
                 )
                 (cond
                   (
                     (member j '(1 2 3)) (- h)
                   )
                   (
                     (member j '(4 5 6)) (/ h -2.)
                   )
                   ( 0. )
                 )
               )
            )
            (dx 71 l)
          )
        )
      )
    )
  )
   (progn
     (setq matrix
        (list
          (list (cos rotn) (sin (- rotn)) 0.)
          (list (sin rotn) (cos    rotn)  0.)
          (list     0.           0.       1.)
        )
     )

     (mapcar
       (function
         (lambda ( point )
           (mapcar '+
             (mapcar
               (function
                 (lambda ( r ) (apply '+ (mapcar '* r point)))
               )
               matrix
             )
             (reverse (cdr (reverse base)))
           )
         )
       )
       lst
     )
   )
 )
)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...